Closed mira-thakkar closed 5 years ago
if the sign process is being done in the client set a flag that will be true
when any page (except the signin page) is loaded, and if it's true use Router.back()
otherwise don't.
I think Router.back()
which seems to just call window.history.back()
is not ideal for this use case in general because the resulting state of the history, i.e. forward button will go to the login page again, is unexpected to the user.
You could in theory keep track of previously visited pages using a global state. It's not up to the Next.js router to track this as we just use browser APIs / state
I am building react js app based on nextjs boilerplate.
Expected Behavior
Check if router has previous url or not.
Current Behavior
The tab is being closed on router.back()
Steps to Reproduce (for bugs)
router.back()
Context
I need to get the previous url to redirect the user back to the page after signin in my app. It works fine if there is any other page visited before the signin page. But when user directly open signin page in new tab, there will be no previous url. So in router.back() it closes the tab.
Your Environment