如何使用jQuery或纯JavaScript将用户从一个页面重定向到另一个页面?
您何时设置locationURL字符串而不是设置location.href?
location = "http://www.stackoverflow.com";
Run Code Online (Sandbox Code Playgroud)
VS
location.href = "http://www.stackoverflow.com";
Run Code Online (Sandbox Code Playgroud)
我正在使用react-router,这意味着我将路由存储在app.tsx文件中。
我有需要重定向到外部 url 的卡片组件onClick。
所以我的问题是如何onClick使用外部 url 示例重定向卡组件:www.test.com并为该 url 提供两个查询字符串a=xxx和b=xxx
我刚开始反应并在组件中包含此链接:
<a href="https://example.com/faq.html"> FAQ </a>
Run Code Online (Sandbox Code Playgroud)
我想服务器faq.html外部反应。
问题是反应将链接视为内部链接并给出 404。
我看到了一个类似的问题,建议使用<Route ...,但是我不知道如何将超链接转换为路由。
我也知道我可以添加target="_blank"到标签中,但这不是我理想的解决方案。
因此,感谢您帮助解决此问题。
我有一个页面验证用户并在验证成功时将其重定向到登录页面.但是,使用redirectURL更改但Login不呈现新页面.如何才能渲染新页面?
App.js
var child;
render() {
if (this.state.toLogin && !this.state.mounted) {
<Route exact path="/Login" component={Login} />;
<Route exact strict path="/" render={({location}) => {
if (location.pathname === window.location.pathname) {
return <Redirect to="/Login"/>;
}
return null;
}}
return(
<div className="App">
<ReactCSSTransitionGroup
transitionName="remove"
transitionEnterTimeout={100}
transitionLeaveTimeout={100}>
{child}
</ReactCSSTransitionGroup>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
Index.js
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)
编辑:根据答案进行更改,但现在URL没有更改,页面也没有呈现