Match Error with useSearch inside a route nested in a layout and pathless route group #2501
Send to my agentWhich project does this relate to?#
Router
Describe the bug#
Using a layout inside a pathless route group directory breaks useSearch. After calling the hook inside the route or the layout, with the correct from value, it gives the error: Invariant failed: Could not find an active match from '/_layout/about'.
I also noticed that the from property type is inferred as __layout/about_, which isn't good for consistency, as the from property in the Link component is inferred as /about.
Your Example Website or App#
https://stackblitz.com/edit/github-qwwxnn?file=src%2Froutes%2F(test)%2F_layout.about.tsx
Steps to Reproduce the Bug or Issue#
- Go to https://stackblitz.com/edit/github-qwwxnn?file=src%2Froutes%2F(test)%2F_layout.about.tsx
- Click on About Link.
- See the error on the page.
Expected behavior#
The useSearch hook should infer the same from types as the Link component, and it should not throw an error.
Screenshots or Videos#
Platform#
- OS: [Windows]
- Browser: [Chrome]
- Version: [^1.64.0]
Additional context#
No response
SeanCassiere added labelsbug
I have the same error when using useLoaderData, useMatch.
route groups are now not removed from the route id anymore to be consistent between types and runtime.
@schiller-manuel , thanks a lot for the quick fix!
For consistency, can’t we have the same values inferred in the
fromprop of theLinkcomponent? Using'/(test)/_layout/about' instead of just'/about'inuseSearchfeels odd.while both are named
from, they referenced different concepts.frominuseSearchis a route idwhereas
fromin<LInk>is a route pathbtw, you can also use
Route.useSearch()so you don't have to type this out.while both are named
from, they referenced different concepts.frominuseSearchis a route idwhereas
fromin<LInk>is a route pathbtw, you can also use
Route.useSearch()so you don't have to type this out.I'm familiar with
Route.useSearch(), but I usually need it outside the route file, and managing its exports/imports isn't ideal because they're default and have generic route names. I'm also trying to avoid circular dependencies, if that makes sense.Thanks for taking time to answer this.
Sign in to join this conversation.
Runtime
routeIdis incorrect.