React-router: How to do anchor aka "hash" links?

Created on 1 Jul 2015  路  11Comments  路  Source: ReactTraining/react-router

Say I have some <div id="my-section"> ... </div>, how do I link to this section of the page? This is a really useful feature of the web.

Most helpful comment

I do see as problematic that the re-render is triggered, since navigating within sections on the same page then causes an unnecessary performance overhead.

Is there any supported way to prevent re-rendering while using named anchors to sections on the same page?

All 11 comments

+1

I can't remember if I closed this because I found a duplicate issue or if I actually figured out how to do it. Anybody know the status of this feature?

+1

I use history locations only and want the original behavior for hashlinks back!

how do you do this?

+1

@darobin Can you please provide details about how did you fix the normal anchor links? Using a[href="#some_id"] still calls createBrowserHistory() leading to a full React re-render.

@pratyushmittal I haven't checked but I believe in my case it is also still re-rendering. After all, it does change the route. But it works: the browser navigates to the hash, which is the desired behaviour. In my case the re-render isn't an issue, the route only affects topmost components, the rest won't see the change.

I do see as problematic that the re-render is triggered, since navigating within sections on the same page then causes an unnecessary performance overhead.

Is there any supported way to prevent re-rendering while using named anchors to sections on the same page?

Any progress on this subject? I wonder why the issue is closed. React is still re-rendering pages.

As a workaround, I think you can respond to LOCATION_CHANGE and perform reconciliation based on the hash property of the payload.

Any progress here? If there is duplicate issue, can anyone please provide URL of that issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wzup picture wzup  路  3Comments

misterwilliam picture misterwilliam  路  3Comments

hgezim picture hgezim  路  3Comments

jzimmek picture jzimmek  路  3Comments

ackvf picture ackvf  路  3Comments