Skip to content

Commit

Permalink
Properly decode element id when emulating hash scrolling (#10682)
Browse files Browse the repository at this point in the history
Co-authored-by: istarkov <istarkov@gmail.com>
  • Loading branch information
brophdawg11 and istarkov committed Jul 7, 2023
1 parent 26dce23 commit 4e4c08a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/decode-hash-scroll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router-dom": patch
---

Properly decode element id when emulating hash scrolling via `<ScrollRestoration>`
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,4 @@
- yionr
- yuleicul
- zheng-chuang
- istarkov
4 changes: 3 additions & 1 deletion packages/react-router-dom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,9 @@ function useScrollRestoration({

// try to scroll to the hash
if (location.hash) {
let el = document.getElementById(location.hash.slice(1));
let el = document.getElementById(
decodeURIComponent(location.hash.slice(1))
);
if (el) {
el.scrollIntoView();
return;
Expand Down

0 comments on commit 4e4c08a

Please sign in to comment.