Skip to content
Discussion options

You must be logged in to vote

The router.ts file serves as the central configuration point for your router instance. While it might seem redundant in a small starter project, it's essential for a few key reasons:

  1. Type Safety (Module Augmentation): This is the most important role. TanStack Router uses TypeScript's module augmentation to provide global type safety. By defining the router in its own file and declaring the Register interface there, you ensure that hooks (like useNavigate), and <Link> components everywhere in your app are fully typed.

    import { createRouter } from '@tanstack/react-router'
    import { routeTree } from './routeTree.gen'
    
    export const router = createRouter({ routeTree })
    
    declare module '@tanst…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mirumodapon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants