T
TanStack16mo ago
stormy-gold

Best practices for getRouteApi() with optional path param?

Are there any best practices for using getRouteApi() when rendering the same element for the index route as well as optional the same route with an optional param? Since TSR doesn't support optional params out of the box we need to define two routes: * /search * /search/playlists It's now not possible to have any rendered routes use the getRouteApi('/search') since it will crash the application with an invariant exception when the child route is rendered. I'm trying to lift as much of the route accessors in the actual route files, but it does mean I'm not able to use the nice route.* hooks for setting search params, etc. Is there any best practices around this?
2 Replies
optimistic-gold
optimistic-gold16mo ago
which invariant exception do you get? can you please post a minimal complete example?
exotic-emerald
exotic-emerald16mo ago
Can you put the param validation into /search/route.tsx ? That should be called for the index route as well as all child routes and should have the right routeAPI I think...

Did you find this page helpful?