Title: [Bug] --router-only main.tsx ignores getRouter() from router.tsx (router.tsx becomes dead code + duplicate Register declaration) · Issue #480 · TanStack/cli · GitHub
Open Graph Title: [Bug] --router-only main.tsx ignores getRouter() from router.tsx (router.tsx becomes dead code + duplicate Register declaration) · Issue #480 · TanStack/cli
X Title: [Bug] --router-only main.tsx ignores getRouter() from router.tsx (router.tsx becomes dead code + duplicate Register declaration) · Issue #480 · TanStack/cli
Description: Which project does this relate to? Create Tanstack App Describe the bug When scaffolding a Router-only SPA (create --router-only), the generated src/router.tsx exports a getRouter() factory, but the generated src/main.tsx does not use it...
Open Graph Description: Which project does this relate to? Create Tanstack App Describe the bug When scaffolding a Router-only SPA (create --router-only), the generated src/router.tsx exports a getRouter() factory, but th...
X Description: Which project does this relate to? Create Tanstack App Describe the bug When scaffolding a Router-only SPA (create --router-only), the generated src/router.tsx exports a getRouter() factory, but th...
Opengraph URL: https://github.com/TanStack/cli/issues/480
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug] --router-only main.tsx ignores getRouter() from router.tsx (router.tsx becomes dead code + duplicate Register declaration)","articleBody":"### Which project does this relate to?\n\nCreate Tanstack App\n\n### Describe the bug\n\nWhen scaffolding a Router-only SPA (`create --router-only`), the generated `src/router.tsx` exports a `getRouter()` factory, but the generated `src/main.tsx` does **not** use it. Instead, `main.tsx` builds its own router inline with `createRouter(...)`.\n\nAs a result:\n\n1. `router.tsx` / `getRouter()` is **dead code** - nothing imports it anywhere in a `--router-only` project.\n2. The `declare module '@tanstack/react-router' { interface Register { ... } }` block is **duplicated** in both `main.tsx` (`router: typeof router`) and `router.tsx` (`router: ReturnType\u003ctypeof getRouter>`).\n\nIn the default (TanStack Start) mode this is fine because Start consumes `getRouter()` from `router.tsx` as the entry, and `main.tsx` is not generated. But in `--router-only` mode the two files diverge and `router.tsx` is left orphaned.\n\n### Your Example Website or App\n\npnpx @tanstack/cli create --router-only\n\n### Steps to Reproduce the Bug or Issue\n\n1. `pnpx @tanstack/cli create --router-only`\n2. Open `src/main.tsx` and `src/router.tsx`\n3. Grep the project for `getRouter` -> only defined in `router.tsx`, never imported\n(No StackBlitz needed - this is reproducible purely from the CLI output.)\n\n### Expected behavior\n\nIn `--router-only` mode, `main.tsx` should import and use `getRouter()` from `router.tsx`, and the `Register` module augmentation should live in a single place (`router.tsx`). Something like:\n\n```tsx\nimport ReactDOM from 'react-dom/client'\nimport { RouterProvider } from '@tanstack/react-router'\nimport { getRouter } from './router'\n\nconst router = getRouter()\n\nconst rootElement = document.getElementById('app')!\n\nif (!rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement)\n root.render(\u003cRouterProvider router={router} />)\n}\n```\n\nThis keeps a single source of truth for router configuration across both Start and Router-only modes, removes the dead `getRouter()`, and removes the duplicate `Register` declaration.\n\n### Screenshots or Videos\n\n_No response_\n\n### Platform\n\n- OS: macOS\n- @tanstack/cli: 0.69.5\n\n### Additional context\n\n- `packages/create/src/frameworks/react/project/base/src/main.tsx.ejs`\n- Line 1: `\u003c% if (!routerOnly) { ignoreFile() } %>` -> only emitted for router-only\n- Lines 6-16: creates its own `router` + declares `Register` instead of importing `getRouter`\n- `packages/create/src/frameworks/react/project/base/src/router.tsx.ejs`\n- No `ignoreFile()` guard -> always emitted, exports `getRouter()` + declares `Register`\n\nThe Solid templates have an identical structure:\n- `packages/create/src/frameworks/solid/project/base/src/main.tsx.ejs`\n- `packages/create/src/frameworks/solid/project/base/src/router.tsx.ejs`","author":{"url":"https://github.com/gs0428","@type":"Person","name":"gs0428"},"datePublished":"2026-06-25T12:54:42Z","url":"https://github.com/TanStack/cli/issues/480"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ee8cbd5c-ef06-df13-444d-d5f7adec1abc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0B2:1A28DE:1940AA:238381:6AF9A250 |
| html-safe-nonce | a5be1914ac65db3e2b7fb8d39b0c7c23768936060428a0541b9e8cc3a95454db |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEIyOjFBMjhERToxOTQwQUE6MjM4MzgxOjZBRjlBMjUwIiwidmlzaXRvcl9pZCI6IjI0MDgxNTc3MDA0NTg5MTQzODQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f023f685a8a061881f71a7e65020830519176e1cff3c8d2ba7229712a5bb37a5 |
| hovercard-subject-tag | issue:4743980283 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TanStack/cli/480/issue_layout |
| twitter:image | https://opengraph.githubassets.com/79a8ffc279b3b148d2fd2dd890d55b118dc40e981d7502a2e0c0ee264eebb4ab/TanStack/cli/issues/480 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/79a8ffc279b3b148d2fd2dd890d55b118dc40e981d7502a2e0c0ee264eebb4ab/TanStack/cli/issues/480 |
| og:image:alt | Which project does this relate to? Create Tanstack App Describe the bug When scaffolding a Router-only SPA (create --router-only), the generated src/router.tsx exports a getRouter() factory, but th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gs0428 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| turbo-cache-control | no-preview |
| go-import | github.com/TanStack/cli git https://github.com/TanStack/cli.git |
| octolytics-dimension-user_id | 72518640 |
| octolytics-dimension-user_login | TanStack |
| octolytics-dimension-repository_id | 932949058 |
| octolytics-dimension-repository_nwo | TanStack/cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 932949058 |
| octolytics-dimension-repository_network_root_nwo | TanStack/cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 072e34035c13c31543fba9f025cbbbda4210dae4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width