-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(next/client): keep hash when navigating from app to pages router (#…
…56223) ### What? Fixes the pages router not receiving a hash when being linked from the app router. ### Why? The hash being removed breaks sites that rely on it for client side features. ### How? The hash gets omitted from the URL when used as a key for the preflightCache. Once it's clear that it's an external URL and that it's not empty we can use the initial href to send the hash as well. Not completely sure if there's an edge case that might break, I added an extra check for when the hash is only used to scroll the page. This might need an additional test case just for `navigate-reducer.test.tsx`. Fixes #56212 --------- Co-authored-by: Zack Tanner <[email protected]> Co-authored-by: JJ Kasper <[email protected]>
- Loading branch information
1 parent
a970f28
commit a2f9ef5
Showing
4 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/navigation/app/hash-link-to-pages-router/global.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-size: 14px; | ||
line-height: 1; | ||
} |
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/navigation/app/hash-link-to-pages-router/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Link from 'next/link' | ||
import './global.css' | ||
|
||
export default function HashPage() { | ||
return ( | ||
<div style={{ fontFamily: 'sans-serif', fontSize: '16px' }}> | ||
<p>Hash To Pages Router Page</p> | ||
<Link href="/some#non-existent" id="link-to-pages-router"> | ||
To pages router | ||
</Link> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters