[英]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. 我的RestAPI服务器将用户请求重定向到另一个网页(例如google.com)如何将我的前端重定向到该页面,我的意思是我有一个按钮,当我按下它时会向我的服务器发送一个axios请求。 my server redirects it to another web page, and I want to show to my client that web-page
我的服务器将其重定向到另一个网页,我想向我的客户端显示该网页
I have made an axios 我做了一个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. 您可以使用
window.location
将当前页面重定向到从服务器或window.open
接收的URL,以在另一个选项卡中打开该页面。
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. 您必须检查
result
对象以确定如何获取重定向URL,但是一旦拥有它,这些将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.