简体   繁体   中英

how to redirect User to another web-page

My RestAPI server redirects a user request to another webpage (for example google.com) how can I redirect my fron-end to that page, I mean I have a button, when I press on it sends an axios request to my server. my server redirects it to another web page, and I want to show to my client that web-page

I have made an axios

 const url = "https://cors-anywhere.herokuapp.com/http://147.13.121.244:4001/redirect"
const client = axios.create({
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Basic a3p0ZXN5547asdhMnFUdVZN',

  }
});

let result = await client.get(url, {}).then((response) => {
  return response
}).catch((error) => {
  return error
})

You can use window.location to redirect the current page to the URL you receive from the server or window.open to open that page in another tab.

For example:

const redirectURL = // result.redirect
// Redirect
window.location = redirectURL;
// New Window
window.open(redirectURL, "_blank");

You'll have to examine the result object to figure out how exactly to get the redirect URL, but once you have it, these will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM