Confusion about router.ts in the project structure
#6842
-
|
Hi there, I created my first @TanStack/router project with following the documentaion. I noticed that the code in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The
If you see the same initialization in |
Beta Was this translation helpful? Give feedback.
The
router.tsfile 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: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
Registerinterface there, you ensure that hooks (likeuseNavigate), and<Link>components everywhere in your app are fully typed.