Replies: 5 comments 13 replies
-
Pathless routes work great for this, wrap all your child routes in another parent route that only has an error element. createBrowserRouter([
{
path: "/",
element: <Layout />,
children: [
{
// has nothing but an error element
errorElement: <ErrorPage />,
// and then put the children under this route:
children: [
{
path: "",
element: <Home />,
},
{
path: "cart",
element: <Cart />,
},
// ... etc.
],
},
],
},
]); Now any errors inside of the children will render inside of the |
Beta Was this translation helpful? Give feedback.
-
How would you do this when using createRoutesFromElements (which I much prefer over the above - easier to visualise the routes) ? |
Beta Was this translation helpful? Give feedback.
-
I think what you want to do here is return a |
Beta Was this translation helpful? Give feedback.
-
Hi @AMoktar Here is another approach with pathless routes, I added a catch-all route as a child route using the const router = createBrowserRouter([
{
path: "/",
element: <MainLayout />,
errorElement: <ErrorPage />,
children: [
{
path: "*",
element: <ErrorPage />,
},
{
path: "home",
element: <Home />,
},
{
/* Add any routes you'd like */
}
]
}
]); |
Beta Was this translation helpful? Give feedback.
-
This guy's solution worked for me |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello guys, I'm wondering if I can render errorElement inside the outlet so, I don't lose my layout design ?
open to any ideas
thanks
Beta Was this translation helpful? Give feedback.
All reactions