0

I need to know, How can I load (redirect) to a particular page(using react-router) after browser session is closed? Suppose, i have logged in and visiting edit-profile page, but i closed the browser, if i open the website again, i could get logged in(as the user details are saved in local storage), but how can i redirect the user to edit-profile page.

I tried the below solution, but i wont have history session once the browser is shut. What is the best way to redirect a page using React Router?

Anand Kumar
  • 99
  • 2
  • 6
  • I would save the current (or previous) page name in the user details in local storage then use the [session storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) to detect whenever the user open a new session. – Dyo Jan 04 '19 at 15:29
  • @Dyo Can't it be done through **React-router**? The session storage seems like more manual way of doing. – Anand Kumar Jan 04 '19 at 16:21
  • I don't think React-router has a built-in way to do this, another option is to check if the react router `history.length` equals 1 for a new session but I'm unsure if you can rely on it at 100%. – Dyo Jan 04 '19 at 16:36

0 Answers0