Skip to content

[Bug]: if no route match current URL - pathless route with errorElement or ErrorBoundary doesn't catch this error. Only root route error element catches, so error element is not rendered in outlet #10893

@lone-cat

Description

@lone-cat

What version of React Router are you using?

6.16.0

Steps to Reproduce

Just enough to follow the tutorial on the page https://reactrouter.com/en/main/start/tutorial

Expected Behavior

Not found error shoud be displayed (catched) inside pathless route wrapper (inside layout) as in tutorial, I think

Actual Behavior

In totorial "not found" component is said to be rendered inside root route's layout but actually it does not. As i can see - throwing error in route is catched and error element is being rendered inside layout (in outlet).
for example if i add into pathless route at the end such component:

[
  ....
  {
    path: '*',
    Component: () => { throw new Error() }
  }
]

it renders properly inside outlet. But not found errors bubble up to root route and only there are catched, and error element is shown directly on the page but not in outlet.
Actually other people also face same problem, for example: https://stackoverflow.com/questions/75179651/how-can-i-make-a-pathless-route-render-correctly-inside-outlet-in-react-router
I don't know if it is a bug in router or in docs =) And sorry if I've filled this form improperly - I'm creating first issue in my life =)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions