{"record":{"id":"62aecee54f841012","repo":"remix-run/react-router","slug":"you-cannot-use-navigator-push-on-the-server-beca","errorCode":null,"errorMessage":"You cannot use navigator.push() on the server because it is a stateless environment. This error was probably triggered when you did a `navigate(${JSON.stringify(to)})` somewhere in your app.","messagePattern":"You cannot use navigator\\.push\\(\\) 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":297,"sourceCode":"        ...(val.name !== \"Error\"\n          ? {\n              __subType: val.name,\n            }\n          : {}),\n      };\n    } else {\n      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.`,","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/remix-run/react-router/blob/7aea711dd1ae2bc5a076d13ff17291829690fa74/packages/react-router/lib/dom/server.tsx#L279-L315","documentation":"During SSR, the router runs on a stateless navigator whose push() throws (lib/dom/server.tsx:268): there is no history stack to push onto when rendering a response once. The message includes the offending destination so you can locate the navigate(to) call that ran on the server.","triggerScenarios":"Calling navigate('/path') from useNavigate() during the server render of a component (not inside an effect/handler); invoking router.navigate() during SSR; navigation triggered synchronously in a component body or module scope while server rendering.","commonSituations":"Auth gating done by navigate() in a component instead of a loader redirect; login/onboarding flows calling navigate on mount during SSR; component-level side effects that assume a browser.","solutions":["Do the redirect in the loader/action: throw redirect('/login')","Move navigate() calls into event handlers or effects so they only run client-side","Replace render-time <Navigate>/navigate with loader-level redirects for SSR-visible conditions"],"exampleFix":"// before\nfunction Dashboard() {\n  const navigate = useNavigate()\n  if (!user) navigate('/login') // runs during SSR render\n}\n// after\nexport async function loader({ request }) {\n  if (!await getUser(request)) throw redirect('/login')\n}","handlingStrategy":"validation","validationCode":"const isServer = typeof window === 'undefined';\n// Redirect decisions that must work during SSR belong in loaders:\nexport async function loader({ request }: Route.LoaderArgs) {\n  if (!(await getUser(request))) throw redirect('/login');\n  return null;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do redirects in loaders/actions with redirect(), never in component render","Keep navigate() strictly inside event handlers and effects","Assume any component can render on the server; guard browser-only logic"],"tags":["ssr","navigation","use-navigate","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-14T05:17:10.506Z"}