Skip to content

Match Error with useSearch inside a route nested in a layout and pathless route group #2501

Closed

Description

@Hazihell

Which 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

  1. Go to https://stackblitz.com/edit/github-qwwxnn?file=src%2Froutes%2F(test)%2F_layout.about.tsx
  2. Click on About Link.
  3. 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

Image

Platform

  • OS: [Windows]
  • Browser: [Chrome]
  • Version: [^1.64.0]

Additional context

No response

Activity

  1. added
    bug
    on Oct 10, 2024
  2. SeanCassiere commented on Oct 10, 2024

    @SeanCassiere
    Member

    Runtime routeId is incorrect.

    Image

  3. MarkArchitect commented on Oct 13, 2024

    @MarkArchitect

    I have the same error when using useLoaderData, useMatch.

  4. schiller-manuel commented on Oct 15, 2024

    @schiller-manuel
    Collaborator

    route groups are now not removed from the route id anymore to be consistent between types and runtime.

  5. roger-serra-leanon commented on Oct 17, 2024

    @roger-serra-leanon

    @schiller-manuel , thanks a lot for the quick fix!

    For consistency, can’t we have the same values inferred in the from prop of the Link component? Using '/(test)/_layout/about' instead of just '/about' in useSearch feels odd.

    Image

  6. schiller-manuel commented on Oct 17, 2024

    @schiller-manuel
    Collaborator

    while both are named from, they referenced different concepts.
    from in useSearch is a route id

    whereas from in <LInk> is a route path

    btw, you can also use Route.useSearch() so you don't have to type this out.

  7. roger-serra-leanon commented on Oct 17, 2024

    @roger-serra-leanon

    while both are named from, they referenced different concepts. from in useSearch is a route id

    whereas from in <LInk> is a route path

    btw, 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions