import Link from 'next/link' import ReactDOM from 'react-dom/server' import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtime' import { useRouter } from 'next/router' function RouterComp(props) { const router = useRouter() if (!router) { throw new Error('router is missing!') } return ( <>

props {JSON.stringify(props)}

router: {JSON.stringify(router)}

) } export async function getServerSideProps({ req, query, preview }) { // this ensures the same router context is used by the useRouter hook // no matter where it is imported console.log( ReactDOM.renderToString(

hello world

) ) return { props: { url: req.url, world: 'world', time: new Date().getTime(), }, } } const Page = ({ world, time, url }) => { if (typeof window === 'undefined') { if (url.startsWith('/_next/data/')) { throw new Error('invalid render for data request') } } return ( <>

hello {world}

time: {time} to non-json
to another
to something
to normal
to slow
to dynamic to broken
to another dynamic to something?another=thing
to redirect-page
to rewrite-source/foo ) } export default Page