Fix navigation from global-not-found to app routes

parent 50bf604f
......@@ -363,13 +363,14 @@ function updateRenderTreeOnNavigation(
// case, because it acts like a root layout, but in the router tree, it
// is rendered in the same position as app/layout.tsx.
//
// Any navigation to the global Not Found route should trigger a
// Any navigation to or from the global Not Found route should trigger a
// full-page navigation.
//
// TODO: We should probably model this by changing the key of the root
// segment when this happens. Then the root layout check would work
// as expected, without a special case.
newSegment === NOT_FOUND_SEGMENT_KEY
newSegment === NOT_FOUND_SEGMENT_KEY ||
oldRenderTree.segment === NOT_FOUND_SEGMENT_KEY
) {
return null
}
......
import { Client } from './client'
import Link from 'next/link'
export default function GlobalNotFound() {
return (
......@@ -7,6 +8,7 @@ export default function GlobalNotFound() {
<body>
<h1 id="global-error-title">global-not-found</h1>
<Client />
<Link href="/">Return home</Link>
</body>
</html>
)
......
......@@ -28,6 +28,18 @@ describe('global-not-found - basic', () => {
expect(notFoundHtmlProp).toBe('true')
})
it('should navigate from global-not-found to the app root layout', async () => {
const browser = await next.browser('/does-not-exist')
await browser.elementByCss('a[href="/"]').click()
expect(await browser.elementByCss('p').text()).toBe('hello world')
expect(await browser.elementByCss('html').getAttribute('lang')).toBe('en')
expect(
await browser.elementByCss('html').getAttribute('data-global-not-found')
).toBeNull()
})
it('should render not-found boundary when calling notFound() in a page', async () => {
const browser = await next.browser('/call-not-found')
// Still using the root layout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment