Skip to content

Commit 4e4c08a

Browse files
Properly decode element id when emulating hash scrolling (#10682)
Co-authored-by: istarkov <[email protected]>
1 parent 26dce23 commit 4e4c08a

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

.changeset/decode-hash-scroll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router-dom": patch
3+
---
4+
5+
Properly decode element id when emulating hash scrolling via `<ScrollRestoration>`

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,4 @@
222222
- yionr
223223
- yuleicul
224224
- zheng-chuang
225+
- istarkov

packages/react-router-dom/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,9 @@ function useScrollRestoration({
13841384

13851385
// try to scroll to the hash
13861386
if (location.hash) {
1387-
let el = document.getElementById(location.hash.slice(1));
1387+
let el = document.getElementById(
1388+
decodeURIComponent(location.hash.slice(1))
1389+
);
13881390
if (el) {
13891391
el.scrollIntoView();
13901392
return;

0 commit comments

Comments
 (0)