router icon indicating copy to clipboard operation
router copied to clipboard

Child route incorrectly matches in beta 70

Open byudaniel opened this issue 3 years ago • 3 comments

Describe the bug

In beta 70 a child route of / matches on just /, but the /test route never matches.

const indexRoute = new Route({
  getParentRoute: () => rootRoute,
  path: '/',
  component: () => {
    return (
      <div className="p-2">
        <h3>Index</h3>
        <Outlet />
      </div>
    );
  },
});

const childOfIndexRoute = new Route({
  getParentRoute: () => indexRoute,
  path: 'child',
  component: () => {
    return (
      <div className="p-2">
        <h4>Child of index route</h4>
      </div>
    );
  },
});

const notChildOfIndexRoute = new Route({
  getParentRoute: () => rootRoute,
  path: 'test',
  component: () => {
    return (
      <div className="p-2">
        <h4>Child of index route</h4>
      </div>
    );
  },
});

const routeTree = rootRoute.addChildren([
  indexRoute.addChildren([childOfIndexRoute]),
  notChildOfIndexRoute,
]);

In beta 69 it is the opposite problem, the child route never matches, but the peer "/test" route matches correctly.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-zhfoj7?file=src/main.tsx

Steps to Reproduce the Bug or Issue

  1. On launch notice that the / route is showing "Child of index route"
  2. Go to /test, notice that the child route no longer renders, but the index route incorrectly renders
  3. Update package.json to use beta.69.
  4. Go to the / route and notice that index render successfully
  5. Go to /child and notice it renders successfully
  6. Go to /test and notice that the test route is not rendered

Expected behavior

I would expect / to render just the index route, /child to render the index route plus the content for the child route. I would then expect /test to render only the test route without index content.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Edge
  • Version: 109

Additional context

No response

byudaniel avatar Feb 03 '23 17:02 byudaniel

I’m actually reworking the matching right now. I’ll push a fix soon.

tannerlinsley avatar Feb 03 '23 17:02 tannerlinsley

For the index route, instead of path: '/' if it's id: '/' then it would load the notChildOfIndexRoute correctly. Also, with this the index route would load the first child route as default.

saibs avatar Feb 04 '23 06:02 saibs

Matching should be much better now. It's all described here, too:

  • https://tanstack.com/router/v1/docs/guide/route-paths
  • https://tanstack.com/router/v1/docs/guide/route-matching

tannerlinsley avatar Feb 06 '23 06:02 tannerlinsley