【发布时间】:2019-03-18 11:50:22
【问题描述】:
我有一个代码示例,我试图重定向尚未登录的用户。我正在使用外部身份验证来发送用户通过第 3 方身份验证系统登录。我知道 react-routes 有 Redirect 选项,我知道它们只重定向到路径名。有没有办法让window.assign 发生重定向,从而将用户立即重定向到不同的页面?
提前谢谢你!
const ProtectedRoute = (auth, component: Component, ...rest) => {
return <Route
{...rest}
render={props => auth.isAuthenticated()
? <Component {...props} />
: <Redirect
to={{
pathname: 'http://example.com/',
state: { from: props.location },
}}
/>
}
/>;
};
【问题讨论】:
标签: reactjs react-router