rsnext/test/integration/getserversideprops-preview/pages/index.js
JJ Kasper 9793e9004f
Add isPreview field to router (#21638)
This adds an `isPreview` field to the `next/router` to allow detecting when in preview mode. 

Closes: https://github.com/vercel/next.js/issues/14903
2021-02-18 18:34:33 +00:00

26 lines
639 B
JavaScript

import { useRouter } from 'next/router'
export function getServerSideProps({ res, preview, previewData }) {
// test override in preview mode
res.setHeader('Cache-Control', 'public, max-age=3600')
return {
props: {
hasProps: true,
preview: !!preview,
previewData: previewData || null,
},
}
}
export default function ({ hasProps, preview, previewData }) {
return (
<>
<pre id="props-pre">
{hasProps
? JSON.stringify(preview) + ' and ' + JSON.stringify(previewData)
: 'Has No Props'}
</pre>
<p id="router">{JSON.stringify(useRouter())}</p>
</>
)
}