mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### What Following an anchor link to a hash param, and then attempting to use `history.pushState` or `history.replaceState`, would result in an MPA navigation to the targeted URL. ### Why In #61822, a guard was added to prevent calling `ACTION_RESTORE` with a missing tree, to match other call-sites where we do the same. This was to prevent the app from crashing in the case where app router internals weren't available in the history state. The original assumption was that this is a rare / unlikely edge case. However the above scenario is a very probable case where this can happen, and triggering an MPA navigation isn't ideal. ### How This updates `ACTION_RESTORE` to be resilient to an undefined router state tree. When this happens, we'll still trigger the restore action to sync params, but use the existing flight router state. Closes NEXT-2502
97 lines
2.4 KiB
TypeScript
97 lines
2.4 KiB
TypeScript
import Link from 'next/link'
|
|
|
|
export default function ShallowLayout({ children }) {
|
|
return (
|
|
<>
|
|
<h1>Shallow Routing</h1>
|
|
<div>
|
|
<div>
|
|
<a href="#content" id="hash-navigation">
|
|
Hash Navigation (non-Link)
|
|
</a>
|
|
</div>
|
|
<div>
|
|
<Link href="/a" id="to-a">
|
|
To A
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<a href="/a" id="to-a-mpa">
|
|
To A MPA Navigation
|
|
</a>
|
|
</div>
|
|
<div>
|
|
<Link href="/b" id="to-b">
|
|
To B
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<a href="/b" id="to-b-mpa">
|
|
To B MPA Navigation
|
|
</a>
|
|
</div>
|
|
<div>
|
|
<Link href="/dynamic/1" id="to-dynamic-1">
|
|
To Dynamic 1
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link href="/dynamic/2" id="to-dynamic-2">
|
|
To Dynamic 2
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link href="/pushstate-data" id="to-pushstate-data">
|
|
To PushState Data
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link
|
|
href="/pushstate-new-searchparams"
|
|
id="to-pushstate-new-searchparams"
|
|
>
|
|
To PushState new SearchParams
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link href="/pushstate-new-pathname" id="to-pushstate-new-pathname">
|
|
To PushState new pathname
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link href="/pushstate-string-url" id="to-pushstate-string-url">
|
|
To PushState String Url
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link href="/replacestate-data" id="to-replacestate-data">
|
|
To ReplaceState Data
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link
|
|
href="/replacestate-new-searchparams"
|
|
id="to-replacestate-new-searchparams"
|
|
>
|
|
To ReplaceState new SearchParams
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link
|
|
href="/replacestate-new-pathname"
|
|
id="to-replacestate-new-pathname"
|
|
>
|
|
To ReplaceState new pathname
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link href="/replacestate-string-url" id="to-replacestate-string-url">
|
|
To ReplaceState String Url
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
<div id="content">{children}</div>
|
|
</>
|
|
)
|
|
}
|