Giter Site home page Giter Site logo

Comments (5)

kiliman avatar kiliman commented on April 28, 2024 1

useMatches works on the routes hierarchy, so for a given route, you'll only get matches for each parent route. It doesn't consider other routes that happen to share a partial prefix.

So this works, as <PollDetail> is a child of <Poll>

{
  path: '/',
  element: <Layout />,
  children: [
    {
      path: 'poll',
      element: <Poll />,
      children: [
        {
          path: ':id',
          element: <PollDetail />,
        },
      ],
    },
  ],
}

Instead of this, where <PollDetail> is a sibling of <Poll>. So useMatches will not include matches for sibling routes even though they both have /poll prefix.

{
  path: '/',
  element: <Layout />,
  children: [
    {
      path: '/poll',
      element: <Poll />,
    },
    {
      path: '/poll/:id',
      element: <PollDetail />,
    },
  ],
}

from react-router.

brophdawg11 avatar brophdawg11 commented on April 28, 2024

Can you elaborate on what information you would want to be added and to which pages? Is this an misunderstanding of how breadcrumbs via useMatches work? Or a misunderstanding of the concept of an index route?

from react-router.

irakli2206 avatar irakli2206 commented on April 28, 2024

If I add a few routes as children of another route, it will consider the parent route as a layout wrapping the children. I don't want that to happen. I want the subroutes to be subroutes merely based on the way the paths are structured, i.e. parent page /poll will go to another page of /poll/:poll_id. If I make the routes siblings to each other instead of nesting one into the other, then useMatches won't realize that one route is logically connected to the next route. In other words breadcrumbs can only work for layouts and direct children of layouts. Please read the stackoverflow post, it's explained much better there.

from react-router.

irakli2206 avatar irakli2206 commented on April 28, 2024

I see. I thought there's a way to make it work without nesting. Thanks.

from react-router.

brophdawg11 avatar brophdawg11 commented on April 28, 2024

I do think that the proper nesting and use of index routes is the right solution here, however:

I want the subroutes to be subroutes merely based on the way the paths are structured

It sounds like maybe you just want strict URL-based breadcrumbs and don't care about the route/UI nesting? If so you don't want to use useMatches (which is tightly coupled to the route hierarchy by design as mentioned above) and instead can create your breadcrumbs via the URL segments: useLocation().pathname.split('/')

from react-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.