{"record":{"id":"7ef93a0801615b27","repo":"vercel/next.js","slug":"no-router-instance-found-you-should-only-use-nex","errorCode":null,"errorMessage":"No router instance found.\nYou should only use \"next/router\" on the client side of your app.\n","messagePattern":"No router instance found\\.\nYou should only use \"next/router\" on the client side of your app\\.\n","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/client/router.ts","lineNumber":79,"sourceCode":"  'reload',\n  'back',\n  'prefetch',\n  'beforePopState',\n] as const\n\n// Events is a static property on the router, the router doesn't have to be initialized to use it\nObject.defineProperty(singletonRouter, 'events', {\n  get() {\n    return Router.events\n  },\n})\n\nfunction getRouter(): Router {\n  if (!singletonRouter.router) {\n    const message =\n      'No router instance found.\\n' +\n      'You should only use \"next/router\" on the client side of your app.\\n'\n    throw new Error(message)\n  }\n  return singletonRouter.router\n}\n\nurlPropertyFields.forEach((field) => {\n  // Here we need to use Object.defineProperty because we need to return\n  // the property assigned to the actual router\n  // The value might get changed as we change routes and this is the\n  // proper way to access it\n  Object.defineProperty(singletonRouter, field, {\n    get() {\n      const router = getRouter()\n      return router[field] as string\n    },\n  })\n})\n\ncoreMethodFields.forEach((field) => {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/client/router.ts#L61-L97","documentation":"`getRouter()` in router.ts:74-82 returns the Pages Router singleton. If `singletonRouter.router` is null (never initialized via `createRouter`), it throws this `Error`. The singleton is only populated client-side during hydration, so accessing it on the server or before initialization is the bug the message points at.","triggerScenarios":"Importing `next/router` and calling `useRouter()`/`router.push()` in code that runs on the server (Server Component, `getStaticProps`, `getServerSideProps`, a Node script) or in the browser before the router singleton has been created.","commonSituations":"Using `next/router` (Pages Router API) inside an App Router Server Component; calling router methods at module top-level on the server; SSR of a component that calls `router.push` during render.","solutions":["Use `next/navigation`'s `useRouter` in the App Router, not `next/router`.","Only call `next/router` inside client-only code paths (event handlers, effects), guarded by `typeof window !== 'undefined'` if needed.","Ensure Pages Router pages are hydrated so `createRouter` runs before any router access."],"exampleFix":"// before — App Router Server Component\nimport router from 'next/router'\nexport default function Page() { router.push('/x') /* throws */ }\n\n// after — App Router Client Component\n'use client'\nimport { useRouter } from 'next/navigation'\nexport default function Page() {\n  const router = useRouter()\n  return <button onClick={() => router.push('/x')}>go</button>\n}","handlingStrategy":"type-guard","validationCode":"// Guard server/client boundaries before touching next/router.\nfunction canUsePagesRouter(): boolean {\n  return typeof window !== 'undefined' && !!singletonRouterAvailable()\n}","typeGuard":"function isBrowser(): boolean {\n  return typeof window !== 'undefined'\n}\n// Usage:\nif (isBrowser()) { const router = require('next/router').default }","tryCatchPattern":null,"preventionTips":["Use next/navigation (App Router) instead of next/router in Server Components.","Only call next/router inside client-side event handlers or effects.","Guard with typeof window !== 'undefined' when sharing utilities across server and client."],"tags":["pages-router","app-router","server-components","ssr"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}