javascript - 如何将用户重定向到另一个网页
问题描述
我的 RestAPI 服务器将用户请求重定向到另一个网页(例如 google.com)我如何将我的前端重定向到该页面,我的意思是我有一个按钮,当我按下它时会向我的服务器发送 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
})
解决方案
您可以使用window.location
将当前页面重定向到您从服务器接收到的 URL,或window.open
在另一个选项卡中打开该页面。
例如:
const redirectURL = // result.redirect
// Redirect
window.location = redirectURL;
// New Window
window.open(redirectURL, "_blank");
您必须检查该result
对象以确定如何准确获取重定向 URL,但是一旦您拥有它,这些将起作用。
推荐阅读
- r - 如何在ggplot R中制作双轴
- mysql - 当一组数据可以来自 2 行或更多行时,使用 OFFSET 和 LIMIT 从 MySQL 表中获取数据集
- regex - 在 RegEx 中的匹配项之间插入字符(连字符)
- windows-10 - 继续检查所有实例版本,即使一个在 python 中引发错误?
- sql - SQL / BQ - 使用合并功能从表中更新应用程序名称
- r - Stat 函数 dnorm 失败
- reactjs - 重构 React 组件的渲染方法会导致错误
- javascript - 按顺序从数组中获取每个项目的最佳方法是什么?
- javascript - 由于事件侦听器,我的变量不是全局变量。我需要他们是全球性的
- javascript - 如何将画布完全堆叠在网络摄像头流的顶部?