Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for notFound in getServerSideProps (#18241)
This is a follow-up to #17755 which adds support for returning `notFound` to `getServerSideProps` also
- Loading branch information
Showing
8 changed files
with
169 additions
and
15 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
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
34 changes: 34 additions & 0 deletions
34
test/integration/getserversideprops/pages/not-found/[slug].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,34 @@ | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/router' | ||
|
||
export default function Page(props) { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="gssp">gssp page</p> | ||
<p id="props">{JSON.stringify(props)}</p> | ||
<p id="router-query">{JSON.stringify(router.query)}</p> | ||
<p id="router-pathname">{router.pathname}</p> | ||
<p id="router-as-path">{router.asPath}</p> | ||
<Link href="/"> | ||
<a id="to-index">to /</a> | ||
</Link> | ||
<br /> | ||
</> | ||
) | ||
} | ||
|
||
export const getServerSideProps = ({ query }) => { | ||
if (query.hiding) { | ||
return { | ||
unstable_notFound: true, | ||
} | ||
} | ||
|
||
return { | ||
props: { | ||
hello: 'world', | ||
}, | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
test/integration/getserversideprops/pages/not-found/index.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,34 @@ | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/router' | ||
|
||
export default function Page(props) { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="gssp">gssp page</p> | ||
<p id="props">{JSON.stringify(props)}</p> | ||
<p id="router-query">{JSON.stringify(router.query)}</p> | ||
<p id="router-pathname">{router.pathname}</p> | ||
<p id="router-as-path">{router.asPath}</p> | ||
<Link href="/"> | ||
<a id="to-index">to /</a> | ||
</Link> | ||
<br /> | ||
</> | ||
) | ||
} | ||
|
||
export const getServerSideProps = ({ query }) => { | ||
if (query.hiding) { | ||
return { | ||
unstable_notFound: true, | ||
} | ||
} | ||
|
||
return { | ||
props: { | ||
hello: 'world', | ||
}, | ||
} | ||
} |
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