[Bug] --router-only main.tsx ignores getRouter() from router.tsx (router.tsx becomes dead code + duplicate Register declaration)
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.3k
- Forks
- 185
- Merge medio
- 18 h 45 min
- PR fusionados (30 d)
- 2
Descripción
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. Instead, main.tsx builds its own router inline with createRouter(...).
As a result:
router.tsx/getRouter()is dead code - nothing imports it anywhere in a--router-onlyproject.- The
declare module '@tanstack/react-router' { interface Register { ... } }block is duplicated in bothmain.tsx(router: typeof router) androuter.tsx(router: ReturnType<typeof getRouter>).
In 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.
Your Example Website or App
pnpx @tanstack/cli create --router-only
Steps to Reproduce the Bug or Issue
pnpx @tanstack/cli create --router-only- Open
src/main.tsxandsrc/router.tsx - Grep the project for
getRouter-> only defined inrouter.tsx, never imported
(No StackBlitz needed - this is reproducible purely from the CLI output.)
Expected behavior
In --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:
import ReactDOM from 'react-dom/client'
import { RouterProvider } from '@tanstack/react-router'
import { getRouter } from './router'
const router = getRouter()
const rootElement = document.getElementById('app')!
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement)
root.render(<RouterProvider router={router} />)
}
This 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.
Screenshots or Videos
No response
Platform
- OS: macOS
- @tanstack/cli: 0.69.5
Additional context
packages/create/src/frameworks/react/project/base/src/main.tsx.ejs- Line 1:
<% if (!routerOnly) { ignoreFile() } %>-> only emitted for router-only - Lines 6-16: creates its own
router+ declaresRegisterinstead of importinggetRouter packages/create/src/frameworks/react/project/base/src/router.tsx.ejs- No
ignoreFile()guard -> always emitted, exportsgetRouter()+ declaresRegister
The Solid templates have an identical structure:
packages/create/src/frameworks/solid/project/base/src/main.tsx.ejspackages/create/src/frameworks/solid/project/base/src/router.tsx.ejs
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza por packages/create/src/frameworks/react/project/base/src/main.tsx.ejs y router.tsx.ejs, y compara después las plantillas correspondientes de Solid. Ejecuta la CLI con --router-only e inspecciona los archivos generados; se considera terminado cuando main.tsx usa getRouter() y la configuración del router y la declaración de Register ya no están duplicadas en el proyecto generado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- cli, tooling
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 76/100