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

Components don't re-render when hash location changes #292

Closed
mzabriskie opened this issue Sep 16, 2014 · 9 comments
Closed

Components don't re-render when hash location changes #292

mzabriskie opened this issue Sep 16, 2014 · 9 comments

Comments

@mzabriskie
Copy link
Contributor

When my route changes from /user/123 to /user/456 my handler doesn't update to reflect the new user ID.

@mzabriskie
Copy link
Contributor Author

This is not actually an issue, just a misunderstanding of how the router works. The component doesn't get re-initialized and componentWillMount does not get called when the route changes. You have to leverage componentWillReceiveProps. See the master-detail example https://github.com/rackt/react-router/blob/master/examples/master-detail/app.js#L155

@ryanflorence
Copy link
Member

Some links worth noting:

If you read #97 you can see my worry that people would get confused, but hopefully they will find this ticket when they start googling.

@alansouzati
Copy link

I'm facing a similar issue:

I access a URL, for example:

http://localhost:900/test

I click in an anchor link, so the URL changes and my page scrolls to the anchor, so far so good.

http://localhost:900/test#my-anchor

Now, i press the back button in the Browser, the location changes back to http://localhost:900/test but the page does not scroll back to the top.

Any ideas what's going on?

I'm using react-router 0.13.4

@alansouzati
Copy link

Never mind folks, the problem was with my CSS overriding the default browser behavior with position absolute and overflow hidden.

@knowbody
Copy link
Contributor

knowbody commented Oct 6, 2015

@alansouzati yeah the back button takes you back to the place where you came from, that's the expected behaviour.

If you want to scroll back to the top you need to handle it yourself. (window.scrollTo(0, 0))

@droarty
Copy link

droarty commented Nov 9, 2015

This may just be an update of the broken link above but an excellent resource is the LifeCycle explanation in react-router's docs: https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ComponentLifecycle.md

@alexwakeman
Copy link

The fact that hash changes don't trigger a render is extremely counter-intuitive and indicative of design flaws in this router. I am now resorting to building my own router.

@taion
Copy link
Contributor

taion commented Aug 31, 2016

Hash changes do trigger a render, BTW.

@JohnnyFun
Copy link

fwiw, I ran into the same thing. It came down to me being confused that a nested component wasn't having it's componentWillReceiveProps called. That was happening because I wasn't using all the way down.

Once I wrapped components in that who needed to do routing stuff, all was well in the land of code.

Nice work on this router guys--really makes decoupling routing from UI slick. Much appreciated.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants