0

For example I have this routes:

  • /login: for login screen
  • /home: for home screen

At Home screen, I logout, and I want it come to again /login screen as loading new page (so all states are new). How can I do that in React using React router.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107
  • `window.location = '/login'` ? Can you provide more context? React doesn't provide routing. How do you currently do the routing? – Felix Kling May 16 '17 at 18:43
  • I have edited my question. I'm using React Router library. thanks for your comment. – Trần Kim Dự May 16 '17 at 18:44
  • Possible duplicate of [Programmatically navigate using react router](http://stackoverflow.com/questions/31079081/programmatically-navigate-using-react-router) – Yury Tarabanko May 16 '17 at 18:57

1 Answers1

0

You can 'redirect' like this:

import { browserHistory } from "react-router";

browserHistory.push('/someroute');

And if you want to reset your state - do it in componentWillReceiveProps

  componentWillReceiveProps(nextProps) {
  var currentLocation = nextProps.location.pathname;
  if(currentLocation=='someroute')
    //your logic
  }
kurumkan
  • 2,635
  • 3
  • 31
  • 55