Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: layout routes shouldn't match their parent's path #8085

Closed
ryanflorence opened this issue Sep 29, 2021 · 2 comments
Closed

[Bug]: layout routes shouldn't match their parent's path #8085

ryanflorence opened this issue Sep 29, 2021 · 2 comments

Comments

@ryanflorence
Copy link
Member

ryanflorence commented Sep 29, 2021

What version of React Router are you using?

v6

Steps to Reproduce

<Routes>
  <Route element={<Layout />}/>
    <Route path="/privacy" element={<Privacy />} />
  </Route>
  <Route index element={<Index />} />
</Routes>

Visit "/"

Expected Behavior

The index route should render. The layout shouldn't match.

Actual Behavior

The layout route renders!

At first I was thinking index routes just need to rank higher, but realized that a layout route, without any matching children, shouldn't even be matching in the first place.

<Layout/> shouldn't match "/", it should only match "/privacy".

If you reorder the routes it works:

<Routes>
  <Route index element={<Index />} />
  <Route element={<Layout />}/>
    <Route path="/privacy" element={<Privacy />} />
  </Route>
</Routes>

But v6 is smarter than that.

A good test case might not involve index routes at all and just assert the layout route doesn't match if its child routes don't match.

@timdorr
Copy link
Member

timdorr commented Sep 29, 2021

Just a heads up: your example where you reorder the routes is the same code as above.

mjackson added a commit that referenced this issue Oct 3, 2021
@mjackson
Copy link
Member

mjackson commented Oct 3, 2021

This was fixed in 6ab98d3 and will be released in beta.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants