{"id":19336280,"url":"https://github.com/unlikelystudio/react-router-next","last_synced_at":"2025-07-28T17:08:24.030Z","repository":{"id":224573963,"uuid":"413856716","full_name":"unlikelystudio/react-router-next","owner":"unlikelystudio","description":"POC - Use react-router  with next.js","archived":false,"fork":false,"pushed_at":"2021-10-05T15:12:56.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-24T07:50:33.815Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unlikelystudio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-10-05T14:39:53.000Z","updated_at":"2021-10-05T16:35:40.000Z","dependencies_parsed_at":"2024-02-26T18:00:02.828Z","dependency_job_id":"048c80e4-9e94-4697-b1c0-cc7e00556da9","html_url":"https://github.com/unlikelystudio/react-router-next","commit_stats":null,"previous_names":["unlikelystudio/react-router-next"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/unlikelystudio/react-router-next","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlikelystudio%2Freact-router-next","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlikelystudio%2Freact-router-next/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlikelystudio%2Freact-router-next/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlikelystudio%2Freact-router-next/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unlikelystudio","download_url":"https://codeload.github.com/unlikelystudio/react-router-next/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlikelystudio%2Freact-router-next/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267552097,"owners_count":24106000,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T03:10:29.118Z","updated_at":"2025-07-28T17:08:23.985Z","avatar_url":"https://github.com/unlikelystudio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Building a single page application with Next.js and React Router\n\n### The approach\n\nThe basic idea:\n\n1. Create a custom App (`/pages/_app.tsx`)\n\n2. Return `null` if `typeof window === \"undefined\"`. This is required to prevent react-router from throwing errors during the SSR step!\n\n```tsx\n// pages/_app.tsx\n\nimport { AppProps } from 'next/app';\n\nfunction App({ Component, pageProps }: AppProps) {\n  return (\n    \u003cdiv suppressHydrationWarning\u003e // \u003c- ADD THIS\n      {typeof window === 'undefined' ? null : \u003cComponent {...pageProps} /\u003e}\n    \u003c/div\u003e\n  );\n}\n\nexport default App;\n```\n\n3. Use optional catch all to catch all routes in the `/spa` path. You have to create a `pages/spa/[[...slug]].tsx` file inside the directory of your next app.\n\n4. Use the `StaticRouter` component to not bypass the history of the next router.\n5. You have to manually feed the `Switch` component from `react-router` with a custom location object.\n\n```tsx\n// pages/spa/[[...slug]].tsx\nconst router = useRouter();\n\n\u003cSwitch\n  location={{\n    pathname: router.asPath,\n    search: \"\",\n    state: \"\",\n    hash: \"\",\n  }}\n\u003e\n  ...\n\u003c/Switch\u003e;\n```\n\n6. Replace all the `Link` and `NavLink` components from `react-router` by `NextLink`. All the `Redirect` components by a call to the `router.push` method of the `next-router`.\n\n\u003e ⚠️ As you can't use the `Link` component from `react-router` anymore nested routes will no longer work as expected. You need to provide the full path of the route to your `NextLink` component.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funlikelystudio%2Freact-router-next","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funlikelystudio%2Freact-router-next","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funlikelystudio%2Freact-router-next/lists"}