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
hello {world}
time: {time} to non-json