Root route component is rendered for non-matching-route path but not for missing resource #2255
Send to my agentWhich project does this relate to?#
Router
Describe the bug#
The component defined in the rootRoute is rendered when a non-matching path riggers the rendering of the notFoundComponent but it is not rendered when a child route trows a notFound() value in its loader.
Your Example Website or App#
https://stackblitz.com/edit/github-yk78pg-lfpyxu?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue#
- define a root route with
componentandnotFoundComponent - navigate to a non-matching path
- -> the
componentas well as thenotFoundComponentgets rendered
Expected behavior#
I would expect the behavior to be the same in both scenarios.
Screenshots or Videos#
No response
Platform#
- Version: 1.52.5
Additional context#
No response
SeanCassiere added labelsinformation needed
I’ve used the
quickstart-code-basedas a template. Here is the adjusted version that demonstrates the issue https://stackblitz.com/edit/github-bfat87?file=src%2Fmain.tsxSteps to reproduce:
- In the browser when you are on the home page
- click the "About" link
- -> you see the not found page without menu
- click on "back to home"
- click on "Non-Existing Page" link in the menu
- -> you will see the not-found page but this time with menu
SeanCassiere removed labelsinformation needed
SeanCassiere added labelsbug
Throwing a
notFounderror in a route's loader, outputs the following route-tree.<root.NotFoundComponent />Navigating to a route that DOES NOT EXISTS in the route-tree, results in this route-tree.
<root.Component> <root.NotFoundComponent /> </root.Component>Note that this configuration does not have a
defaultNotFoundComponent.By default the Router has the setting of
notFoundMode: 'fuzzy', where the router traverses up the tree until it finds the nearestnotFoundComponent(which in this case would be the one configured on the root route).Thanks for the further investigation and writing a test-case @SeanCassiere. I haven’t thought about the
non-asynccase.My expected behavior would be that the behavior is consistent across all scenarios, so either the
NotFoundComponentshould be always wrapped or never.@pupuking723, would you mind taking a look and letting us know what you find?
A fix would be welcome if it still reproduces. Please keep it focused on making the root layout consistent between an unmatched path and a loader-thrown notFound(), with regression coverage for both paths if it is still present :)
Thanks for checking @pupuking723!
Sign in to join this conversation.
Please attach a valid minimal reproduction showing off the issue in question.
Edit: Link to a stackblitz starter - https://stackblitz.com/github/tanstack/router/tree/main/examples/react/quickstart-file-based