Skip to content

Updating the URL directly in the browser doesn't affect React Router #22

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

Closed
kartiklad opened this issue Nov 23, 2016 · 3 comments
Closed

Comments

@kartiklad
Copy link
Contributor

I have a very weird issue. I'm not sure if this is expected behaviour or a bug.

Assume that we are on route /example/2 and I change the url of the browser to point to /example. The page reloads but the route loaded is still /example/2

My guess is the redux state store in the Local storage forces the previous route to be reloaded since the route change wasn't triggered from the page itself but the browser url. But I thought this would be handled by the universal routing.

What am I missing here? is there any way I can solve this problem?

@calvinl
Copy link
Member

calvinl commented Nov 24, 2016

@kartiklad Good catch and good guess. You're right, if you disable localStorage in common/js/store/index.dev.js, this issue doesn't happen. What's going on is that the server renders /example, and when the client is loaded, the router's state in the redux store is replaced by the one in localStorage. This is why you see the path flash from /example to /example2 once it loads. Universal routing would not know how to handle that since the server is unaware of what's in localStorage.

I think the solution would be to add a config to avoid syncing the router's state in local storage, which really shouldn't be done anyway. There is more information on the redux-localstorage repository. If you have time, maybe you could submit a PR for it?

@calvinl
Copy link
Member

calvinl commented Nov 24, 2016

To avoid confusion in the future, we could also disable localStorage by default, or remove it from this boilerplate as localStorage is probably a feature that isn't necessary in a barebones setup.

@kartiklad
Copy link
Contributor Author

@calvinl Thanks for the quick revert mate! I did try disabling the localStorage yesterday and it worked as expected, was just wondering if there was a better way.

Anyways, I think I will try and put in a config to avoid router state to be put in local storage. I'll send a PR if I'm successful. But in the meanwhile may be it's worth getting rid of localStorage for this boilerplate, just to avoid future users from questioning their sanity 😉

Will send a PR to remove the local storage. Cheers!

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

2 participants