Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling for 404 in new router (#40787)
- Loading branch information
1 parent
cc1e35d
commit c4647bb
Showing
12 changed files
with
162 additions
and
18 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
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
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,8 @@ | ||
export const NOT_FOUND_ERROR_CODE = 'NEXT_NOT_FOUND' | ||
|
||
export function notFound() { | ||
// eslint-disable-next-line no-throw-literal | ||
throw { | ||
code: NOT_FOUND_ERROR_CODE, | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/app/app/error/ssr-error-client-component/client-component.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,5 @@ | ||
'client' | ||
|
||
export default function Page() { | ||
throw new Error('Error during SSR') | ||
} |
7 changes: 5 additions & 2 deletions
7
test/e2e/app-dir/app/app/error/ssr-error-client-component/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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
'client' | ||
import ClientComp from './client-component' | ||
import { useHeaders } from 'next/dist/client/components/hooks-server' | ||
|
||
export default function Page() { | ||
throw new Error('Error during SSR') | ||
// Opt-in to SSR. | ||
useHeaders() | ||
return <ClientComp /> | ||
} |
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,3 @@ | ||
export default function NotFound() { | ||
return <h1 id="not-found-component">404!</h1> | ||
} |
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,17 @@ | ||
'client' | ||
|
||
import { notFound } from 'next/dist/client/components/not-found' | ||
import React from 'react' | ||
|
||
export default function Page() { | ||
const [notFoundEnabled, enableNotFound] = React.useState(false) | ||
|
||
if (notFoundEnabled) { | ||
notFound() | ||
} | ||
return ( | ||
<button onClick={() => React.startTransition(() => enableNotFound(true))}> | ||
Not Found! | ||
</button> | ||
) | ||
} |
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,9 @@ | ||
// TODO-APP: enable when flight error serialization is implemented | ||
import ClientComp from './client-component' | ||
import { useHeaders } from 'next/dist/client/components/hooks-server' | ||
|
||
export default function Page() { | ||
// Opt-in to SSR. | ||
useHeaders() | ||
return <ClientComp /> | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/app/app/not-found/clientcomponent/client-component.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,7 @@ | ||
'client' | ||
import { notFound } from 'next/dist/client/components/not-found' | ||
|
||
export default function ClientComp() { | ||
notFound() | ||
return <></> | ||
} |
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 @@ | ||
// TODO-APP: enable when flight error serialization is implemented | ||
import { notFound } from 'next/dist/client/components/not-found' | ||
|
||
export default function Page() { | ||
notFound() | ||
return <></> | ||
} |
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