TanStackT
TanStack2y ago
3 replies
progressive-amaranth

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?
Was this page helpful?