rsnext/test/integration/prerender-fallback-aspath/pages/blog/[post]/[comment].js
JJ Kasper 67482914c6
Normalize request URL/asPath for fallback SSG pages (#16352)
This interpolates the dynamic values and rebuilds the request URL for fallback SSG pages since the proxy uses the output path for non-prerendered pages on Vercel which can cause inconsistent request URL/`asPath` values for SSG pages. This also adds tests to ensure the `asPath` is correctly updated

Fixes: https://github.com/vercel/next.js/issues/16269
2020-08-19 15:23:02 +00:00

30 lines
533 B
JavaScript

import { useRouter } from 'next/router'
export default function Comment({ params }) {
const router = useRouter()
if (router.isFallback) return 'Loading...'
return (
<>
<p id="as-path">{router.asPath}</p>
<p id="query">{JSON.stringify(router.query)}</p>
<p id="params">{JSON.stringify(params)}</p>
</>
)
}
export const getStaticProps = ({ params }) => {
return {
props: {
params,
},
}
}
export const getStaticPaths = () => {
return {
paths: [],
fallback: true,
}
}