{"record":{"id":"b97f78fc8a264552","repo":"remix-run/react-router","slug":"you-cannot-use-navigator-replace-on-the-server-b","errorCode":null,"errorMessage":"You cannot use navigator.replace() on the server because it is a stateless environment. This error was probably triggered when you did a `navigate(${JSON.stringify(to)}, { replace: true })` somewhere in your app.","messagePattern":"You cannot use navigator\\.replace\\(\\) on the server because it is a stateless environment\\. This error was probably triggered when you did a `navigate\\((.+?), (.+?)\\)` somewhere in your app\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-router/lib/dom/server.tsx","lineNumber":304,"sourceCode":"      serialized[key] = val;\n    }\n  }\n  return serialized;\n}\n\nfunction getStatelessNavigator() {\n  return {\n    createHref,\n    encodeLocation,\n    push(to: To) {\n      throw new Error(\n        `You cannot use navigator.push() on the server because it is a stateless ` +\n          `environment. This error was probably triggered when you did a ` +\n          `\\`navigate(${JSON.stringify(to)})\\` somewhere in your app.`,\n      );\n    },\n    replace(to: To) {\n      throw new Error(\n        `You cannot use navigator.replace() on the server because it is a stateless ` +\n          `environment. This error was probably triggered when you did a ` +\n          `\\`navigate(${JSON.stringify(to)}, { replace: true })\\` somewhere ` +\n          `in your app.`,\n      );\n    },\n    go(delta: number) {\n      throw new Error(\n        `You cannot use navigator.go() on the server because it is a stateless ` +\n          `environment. This error was probably triggered when you did a ` +\n          `\\`navigate(${delta})\\` somewhere in your app.`,\n      );\n    },\n    back() {\n      throw new Error(\n        `You cannot use navigator.back() on the server because it is a stateless ` +\n          `environment.`,\n      );","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/remix-run/react-router/blob/7aea711dd1ae2bc5a076d13ff17291829690fa74/packages/react-router/lib/dom/server.tsx#L286-L322","documentation":"The stateless SSR navigator's replace() throws (lib/dom/server.tsx:275) for the same reason as push(): server rendering has no history to mutate. It fires when navigate(to, { replace: true }) executes on the server, and the message names the exact call.","triggerScenarios":"navigate('/path', { replace: true }) executed during SSR render (component body, module init, or a server-side router.navigate call); post-form-submit navigation logic that runs during the server render pass.","commonSituations":"Replacing the URL after auth checks or cookie banners during render; form components that navigate on mount with replace; porting client-only logic into SSR'd components.","solutions":["Return/throw a redirect from the loader or action instead","Gate imperative navigation behind user events or useEffect so it never runs during SSR","Move URL normalization (replace) into middleware or the loader where the Response is controlled"],"exampleFix":"// before\nuseEffect(() => {\n  if (searchParams.get('ref')) navigate('/path', { replace: true })\n}, [])\n// still renders on server first render? move to loader:\nexport async function loader({ request }) {\n  const url = new URL(request.url)\n  if (url.searchParams.get('ref')) throw redirect('/path')\n}","handlingStrategy":"validation","validationCode":"const isServer = typeof window === 'undefined';\nuseEffect(() => {\n  if (!isServer && needsReplace) navigate('/path', { replace: true });\n}, []);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use loader redirects for URL cleanup visible to SSR","Keep { replace: true } navigation in event handlers/effects only","Test components with renderToString to catch server-side navigation early"],"tags":["ssr","navigation","replace","stateless-navigator"],"backgroundTag":"navigation-during-ssr","analyzedSha":"7aea711dd1ae2bc5a076d13ff17291829690fa74","analyzedAt":"2026-08-18T18:04:14.938Z","contentChangedAt":"2026-08-18T18:04:14.938Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}