Great question — answering as the UphillTech team:
If you're using Next.js 9.5 or later the correct way to do this is with Rewrites . Do not use a custom server, it makes maintaining and deploying your site much harder and just isn't necessary here. There is a detailed tutorial on how to do this here . The basic idea: Create a custom App ( /pages/_app.tsx ) Return null if typeof window === "undefined" . This is required to prevent react-router from throwing errors during the SSR step! // pages/_app.tsx import { AppProps } from 'next/app'; function App({ Component, pageProps }: AppProps) { return ( <div suppressHydrationWarning> // <- ADD THIS {typeof window === 'undefined' ? null : <Component {...pageProps} />} </div> ); } export default...
Full answer by Colin McDonnell: https://stackoverflow.stackexchange.com/a/64600814 (CC BY-SA 4.0).
Need it done for your business? UphillTech.