diff --git a/.changeset/dirty-coats-warn.md b/.changeset/dirty-coats-warn.md new file mode 100644 index 0000000000..6e46b03b0c --- /dev/null +++ b/.changeset/dirty-coats-warn.md @@ -0,0 +1,5 @@ +--- +"react-router-dom": minor +--- + +Fix elementId not decoded when emulate native hash scroll diff --git a/contributors.yml b/contributors.yml index c32eacce01..1c28dfdb96 100644 --- a/contributors.yml +++ b/contributors.yml @@ -219,3 +219,4 @@ - yuleicul - zheng-chuang - holynewbie +- istarkov diff --git a/packages/react-router-dom/index.tsx b/packages/react-router-dom/index.tsx index dc9edbeca8..df7281cb05 100644 --- a/packages/react-router-dom/index.tsx +++ b/packages/react-router-dom/index.tsx @@ -1354,7 +1354,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;