javascript - How to get current route in react-router 2.0.0-rc5 -
i have router below:
<router history={hashhistory}> <route path="/" component={app}> <indexroute component={index}/> <route path="login" component={login}/> </route> </router> here's want achieve :
- redirect user
/loginif not logged in - if user tried access
/loginwhen logged in, redirect them root/
so i'm trying check user's state in app's componentdidmount, like:
if (!user.isloggedin) { this.context.router.push('login') } else if(currentroute == 'login') { this.context.router.push('/') } the problem here can't find api current route.
i found this closed issue suggested using router.activestate mixin , route handlers, looks these 2 solutions deprecated.
after reading more document, found solution:
https://github.com/reacttraining/react-router/blob/master/packages/react-router/docs/api/location.md
i need access injected property location of instance of component like:
var currentlocation = this.props.location.pathname
Comments
Post a Comment