router icon indicating copy to clipboard operation
router copied to clipboard

navigate method type error

Open metinsut opened this issue 4 years ago • 3 comments

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

Screenshot 2022-12-04 at 19 41 32

Platform

  • os: macOS
  • browser: Chrome -version: "@tanstack/react-router": "^0.0.1-beta.28",

Additional context

No response

metinsut avatar Dec 04 '22 19:12 metinsut

Is there a login route defined on the router?

tannerlinsley avatar Dec 06 '22 02:12 tannerlinsley

yes, I defined it.

https://github.com/metinsut/react-boilerplate-2022/blob/main/src/Routes/Routes.tsx

metinsut avatar Dec 07 '22 10:12 metinsut

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.

tannerlinsley avatar Dec 08 '22 15:12 tannerlinsley