Skip to content

[Bug]: Nested routing (<Routes> inside <RouterProvider />) #10317

@AndrewWebDev

Description

@AndrewWebDev

What version of React Router are you using?

6.10.0

Steps to Reproduce

Example:
I wrote a full example on Codesandbox for reproducing, please have a look:
https://codesandbox.io/s/react-router-v6-action-error-edbuhu?file=/src/business/business.js

image

Explanation:

I use <RouterProvider /> in the root,
but I have another router inside (for my header) where I show components (search, filtering, selectors) depending on routing.
Other words inside the root "Layout" component exist a "Header" component where exist nested routes <Routes><Route.../></Routes>

Steps for reproduce:
Press the button "Submit. Press and get an error." below on the page and get an error.

To fix the problem, comment in the opened file: (business/business.js file)
// export const APP_ENABLE_NESTED_ROUTES = true;

Conclusion:
Nested routes broke errorElement handling. Why?

Thanks for your attention,
Andrii Badekha

Expected Behavior

After pressing the button: "Submit. Press and get an error.",

Expect message on UI:
Exception properly handled in <PageError />

I expect that my "errorElement" will catch an error and process them, but instead, the react-router shows a general error, not my error handler component.

Actual Behavior

After pressing the button: "Submit. Press and get an error.",

Get the error:
Error: Could not find a matching route for the current errors: [object Object]

As a result, my errorElement was missed, I read additionally documentation and seems like it is unexpected behaviour, docs don't cover this case.

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