navigate method type error
Describe the bug
I am getting a type error while using navigate method.
A type declaration I found in the examples solves this problem.
declare module '@tanstack/react-router' {
interface RegisterRouter {
router: typeof router;
}
}
Your Example Website or App
...
Steps to Reproduce the Bug or Issue
import { useRouter } from '@tanstack/react-router';
const { navigate } = useRouter();
//Type Error
navigate({ to: '/login' });
Expected behavior
navigate({ to: '/' }) -> working
navigate({ to: '/login' }); -> not working
Screenshots or Videos
Platform
- os: macOS
- browser: Chrome -version: "@tanstack/react-router": "^0.0.1-beta.28",
Additional context
No response
Is there a login route defined on the router?
yes, I defined it.
https://github.com/metinsut/react-boilerplate-2022/blob/main/src/Routes/Routes.tsx
So if I understand correctly, adding this resolved the issue:
declare module '@tanstack/react-router' { interface RegisterRouter { router: typeof router; } }
If that's the case, then this is correct and expected. For module-imported utilities like Link to know about your routes, you need to register the router with the library in your project.