使用 react-router 登录后自动重定向 [英] Automatic redirect after login with react-router
问题描述
我想在我的 react/react-router/flux 应用程序中构建一个 Facebook 登录.我在登录事件上注册了一个侦听器,如果用户已登录,我想将用户重定向到 '/dashboard'
.我该怎么做?location.push
效果不佳,除非完全重新加载页面.
I wanted to build a Facebook login into my react/react-router/flux application.
I have a listener registered on the login event and would like to redirect the user to '/dashboard'
if they are logged in. How can I do that? location.push
didn't work very well, except after reloading the page completely.
推荐答案
React 路由器 v0.13
Router
实例 从 Router.create
返回可以传递(或者,如果在 React 组件中,您可以从 上下文对象),并包含方法 like transitionTo
可以用来过渡到新路线.
The Router
instance returned from Router.create
can be passed around (or, if inside a React component, you can get it from the context object), and contains methods like transitionTo
that you can use to transition to a new route.
这篇关于使用 react-router 登录后自动重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!