how do I get the current path fully typed?
I have a LocaleSwitcher component which is responsible to change the language of my app.
it basically convert something like app.com/en/... to app.com/de/...
i'm getting this error because I pass a simple string to the navigate.to:
I've tried using the
router.state.location.pathname but it's type is this: (property) ParsedLocation<Partial<{}>>.pathname: string


5 Replies
deep-jadeOP•2y ago
for now using a never to ignore the error:

national-gold•2y ago
So do all of your Routes have this $lang path parameter?
Maybe then getting the location from useRouterState may help in getting a strictly typed output.
deep-jadeOP•2y ago
@Sean Cassiere
this is basically the component i'm trying to build, it's a language switcher that is available everywhere in the app.
it should be able to go from:
http://localhost:5173/#/en/317aa97e-3b15-49f0-80be-866bf9562bfd/menu
to:
http://localhost:5173/#/es/317aa97e-3b15-49f0-80be-866bf9562bfd/menu
national-gold•2y ago
Sorry, been out for a bit.
Would you happen to have a simplified version of this I could play around with? Like in a Stackblitz or something?
national-gold•2y ago
I took a stab at it and came up with this.
https://stackblitz.com/edit/github-bh7q2o?file=src%2Froutes%2F-components%2Flanguage-switcher.tsx
I'm any-casting the
to prop since I'd always know where this component is being called from.Sean Cassiere
StackBlitz
router path param lang switcher - StackBlitz
Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz