URL hashes with lazy loading and default integration #225
orenelbaum
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Also, this needs to consider when the router is using Perhaps better to: function scrollToHash() {
const hash = useLocation().hash;
if (hash) {
try {
const el = document.querySelector(hash);
el && el.scrollIntoView();
} catch (e) {
// ignore bad selector
}
}
} The user would still need to call this |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Using the default integration (with
location.pathname
), when navigating to a URL with a hash, if the route component is lazy loaded, the default behavior of scrolling to the element with the matching ID doesn't work.That's because the browser will try immediately to scroll to the element, but the element isn't rendered yet because of lazy loading.
I became aware of this issue through a support thread in the Discord.
The best solution I found is to add this to the page component
This seems to work fine but I was thinking that maybe it could be nice if this behavior was built in, although I'm not really sure how to achieve this.
Beta Was this translation helpful? Give feedback.
All reactions