【发布时间】:2019-07-16 03:30:41
【问题描述】:
我正在使用 Nodejs 后端为 OAuth 返回一个自定义重定向 URL。我试图让 React 将用户重定向到这个 URL,但是它将 localhost 添加到它的前面。
import React, { Component } from "react";
import { withRouter } from "react-router";
import axios from "axios";
class Test extends Component {
async componentDidMount() {
const profileData = await axios.get("/connect");
this.props.history.push(profileData.data);
}
render() {
return <div />;
}
}
export default withRouter(Test);
假设 profileData.data 返回的字符串是http://www.google.com,网页被重定向到http://localhost:3000/http://www.google.com。
有没有办法使用 React 进行重定向,使其重定向到特定的 URL,而不是尝试重定向到子页面?
【问题讨论】:
-
只有在您留在自己的网站上时,React 路由器才能为您提供帮助。只是一个
window.location.href = profileData.data怎么样?
标签: javascript node.js reactjs redirect react-router