From 4e4c08a76ed1bfaae68a45517cad64139ed8d3db Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Fri, 7 Jul 2023 10:20:56 -0400 Subject: [PATCH] Properly decode element id when emulating hash scrolling (#10682) Co-authored-by: istarkov --- .changeset/decode-hash-scroll.md | 5 +++++ contributors.yml | 1 + packages/react-router-dom/index.tsx | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/decode-hash-scroll.md diff --git a/.changeset/decode-hash-scroll.md b/.changeset/decode-hash-scroll.md new file mode 100644 index 0000000000..212990fbba --- /dev/null +++ b/.changeset/decode-hash-scroll.md @@ -0,0 +1,5 @@ +--- +"react-router-dom": patch +--- + +Properly decode element id when emulating hash scrolling via `` diff --git a/contributors.yml b/contributors.yml index ff676b1da3..69cdb30698 100644 --- a/contributors.yml +++ b/contributors.yml @@ -222,3 +222,4 @@ - yionr - yuleicul - zheng-chuang +- istarkov diff --git a/packages/react-router-dom/index.tsx b/packages/react-router-dom/index.tsx index e2c1539663..d10b1e3d7e 100644 --- a/packages/react-router-dom/index.tsx +++ b/packages/react-router-dom/index.tsx @@ -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;