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 :

  1. redirect user /login if not logged in
  2. if user tried access /login when 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -