Files
JJ KasperGitHubkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
3e9a99c8b0 Fix middleware notFound: true handling (#46759)
This ensures we properly handle rendering the `404` page when `notFound:
true` is returned and middleware is present.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Fixes: https://github.com/vercel/next.js/issues/38239
x-ref: https://github.com/vercel/next.js/issues/43772

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-04 21:35:45 +01:00

54 lines
1.0 KiB
JavaScript

import { useRouter } from 'next/router'
import { useEffect } from 'react'
import { useState } from 'react'
export default function Page(props) {
const router = useRouter()
const [asPath, setAsPath] = useState(
router.isReady ? router.asPath : router.href
)
if (!props.params) {
console.error('props', props)
throw new Error('missing props!!!')
}
useEffect(() => {
if (router.isReady) {
setAsPath(router.asPath)
}
}, [router.asPath, router.isReady])
return (
<>
<p id="ssg">/blog/[slug]</p>
<p id="query">{JSON.stringify(router.query)}</p>
<p id="pathname">{router.pathname}</p>
<p id="as-path">{asPath}</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}
export function getStaticProps({ params }) {
if (params.slug.includes('not-found')) {
return {
notFound: true,
}
}
return {
props: {
now: Date.now(),
params,
},
}
}
export function getStaticPaths() {
return {
paths: ['/ssg/first', '/ssg/hello'],
fallback: 'blocking',
}
}