Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Redirects" should use window.history.replaceState, not window.history.pushState #11

Open
evanpipta opened this issue Apr 6, 2017 · 1 comment

Comments

@evanpipta
Copy link

evanpipta commented Apr 6, 2017

To mimic what users are used, es-router redirects (e.g. when the router is in strict mode) should use the replaceState method, not pushState.

To give an example if why this would be, let's say your base URL is '/foo' and you have route '/bar' added to the router. With pushState and the router in strict mode, if someone visits '/foo/banana', their browser will be sent back to '/foo' automatically because '/banana' isn't a valid route. '/foo' will be pushed to the history. So the history will go from this:
['/foo/banana']
to this:
['/foo/banana', '/foo']

If they try to press the back button, the router is going to detect that change and think they're trying to go back to the second to last item in the history, which is '/foo/banana', and simply push '/foo' into the history again, which will permanently break the back button for the current window (user won't be able to go back to the site they were at before the site using the router).

If replaceState was used instead, a redirect would make the history would go from this:
['/foo/banana']
to this:
['/foo']

which would allow the user to go back to the site they were previously at before visiting the site using the es-router

@evanpipta
Copy link
Author

evanpipta commented Apr 6, 2017

I'll actually work on this along with the other changes I made in my pull request, just putting down the idea now so I don't forget. This should be able to fix all the issues for good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant