T
TanStack4mo ago
rare-sapphire

Native scroll by hash with hash router

Is there any intended way to have the native behavior of scrolling to a DOM element matching a given id in the URL hash, using TSR hash router? I need that for an Electron app, so I am forced not to use the standard default browser router, but I am open to any other solution which works in Electron. Thanks in advance ^_^
9 Replies
extended-salmon
extended-salmon4mo ago
can you give an example please what does not work exactly?
rare-sapphire
rare-sapphireOP4mo ago
I'd need a way to navigate and have the matched view render and scroll to a given scroll point. Using browser router I simply used the hash param, which triggers the default browser behavior of scrolling to the DOM node matching the provided id in the hash. I cannot use browser router in production since I am deploying an Electron app, so I was wondering if there was any way to do that without manually implementing scrolling after render. Switching from browser router to hash router, makes the URL look like this: http://localhost:5173/#example/path#id Which TSR handles correctly but the browser does not scroll to the DOM node with the provided id.
extended-salmon
extended-salmon4mo ago
memory history doesnt work either, right?
rare-sapphire
rare-sapphireOP4mo ago
Exactly, since the URL remains always the same (http://localhost:5173) and every path change or hash adding is performed in memory, the browser cannot tell there is an hash to scroll to. For completeness sake, I just re-tested all this with browser router and the view gets scrolled to the provided id DOM node only on manual reloading, not on the TSR navigation. So, at this point my question becomes: "how can I navigate towards an URL, making the matching view to scroll to a given position?". Thanks again for your time
extended-salmon
extended-salmon4mo ago
can you check if we have any open issue about that on github already?
rare-sapphire
rare-sapphireOP4mo ago
I think that's exactly this: https://github.com/TanStack/router/issues/3741 I am using the last available version, is that fix still not deployed?
GitHub
<Link> with hash prop not working as expected since 1.106.0 · Issu...
Which project does this relate to? Router Describe the bug I noticed for a while that a Link with hash prop isnt working anymore to scroll to that position in the scroll window. In my own code it w...
extended-salmon
extended-salmon4mo ago
GitHub
Release v1.114.33 · TanStack/router
Version 1.114.33 - 4/2/25, 6:43 PM Changes Fix react-router: restore scroll position onResolved (#3914) (9b95618) by Alex Docs router: simplify route variable naming in search params guide (#389...
extended-salmon
extended-salmon4mo ago
if this is not working, can you please create a new github issue including a complete minimal example?
rare-sapphire
rare-sapphireOP4mo ago
Sure, thank you :)

Did you find this page helpful?