Unexpected behavior with not found component specified in the __root
Describe the bug
I specified the notFoundComponent in the root and after I throw a not found error in child route (ex. /$type/$id) I got a warning that telling me that I didn't specified a notFoundComponent in child route, but I want catch it at root level to avoid layout rendering
P.S. I checked documentation and found that router has a notFoundMode field in options, after that I specified a 'root' mode and it didn't help
Your Example Website or App
https://stackblitz.com/edit/github-3cnvav-8s3gis?file=src%2Froutes%2F__root.tsx
Steps to Reproduce the Bug or Issue
- Open page at path /unknown/id
Expected behavior
Route render root notFoundComponent
Screenshots or Videos
No response
Platform
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari, Firefox]
- Version: [e.g. 91.1]
Additional context
No response
If I click on Unknown in your reproducer, I see 123 being rendered which seems to be the root notFoundComponent. Isn't that the expected behavior?
If I click on
Unknownin your reproducer, I see123being rendered which seems to be the rootnotFoundComponent. Isn't that the expected behavior?
But if I open it directly it has unexpected behavior, it opens default tanstack not found component, I'll upload video soon to prove that
https://github.com/TanStack/router/assets/91194878/df06438b-984b-44f0-abd0-d6b421e7b20d
Look at this, when I open it via link on page it works correctly, but if I reload page it shows default not found component with text "Not found", essentially it should has the same behavior as when opening via link
I found the way to fix it, I just wrapped all routes in the layout and added notFoundComponent component to it, but I think when I specify notFoundComponent in the root it should work the same
This is not fixed. In "@tanstack/react-router": "^1.120.20", the root notFoundComponent is ingored in both client navigation and address bar navigation, for both notFoundMode: 'root' and 'fuzzy'
https://stackblitz.com/edit/github-3cnvav-7mr4mpbu?file=src%2Fmain.tsx
https://github.com/user-attachments/assets/09edae08-5587-493b-9cff-be8321f88be5
In case anyone is still interested, what fixed this for me was adding a / to the createRoute definitions -- /my-route lead to this problem, /my-route/ fixed it.