How to handle nested routes with (vite and) react-router? #4501
Replies: 1 comment 2 replies
-
Hi! From what you describe your approach seems pretty much correct, we've been expanding on some examples gradually and have been running into the same types of use cases / scenarios. For example, this is a router configuration I've added while setting up individual pages for orders: const router = createBrowserRouter([
{
Component: App,
children: [
{
path: '/',
Component: Layout,
children: [
{
path: '',
Component: DashboardPage,
},
{
path: 'orders',
Component: OrdersPage,
},
{
path: 'orders/:orderId',
Component: OrderPage,
},
],
},
],
},
]); and navigation: const NAVIGATION: Navigation = [
{
kind: 'header',
title: 'Main items',
},
{
title: 'Dashboard',
icon: <DashboardIcon />,
},
{
segment: 'orders',
title: 'Orders',
icon: <ShoppingCartIcon />,
pattern: 'orders{/:orderId}?',
},
]; For a custom title in the breadcrumbs, the best approach seems to be to check the path from the React Router hooks to set some conditional logic, yes. Let us know if you have any ideas on how that could be better! There should be no need for more For the page container toolbar, the same approach as for customizing the title and breadcrumbs according to the current path seems to be the best way to do it. Again if you think that could be improved somehow let us know! |
Beta Was this translation helpful? Give feedback.
-
I'm just wondering how one is supposed to handle nested routing when using the toolpad.
Currently, on the tutorial page, simple routing (
/
,/orders
,/page-2
) is illustrated. Similarly, on the react-router integration page, it illustrates how to set up react-router with toolpad to render pages within an<Outlet>
, but only 1 level of routing.If one needs to have routes such as
/orders
,/orders/:id
,/orders/:id/foobar
, what would be the right or recommended approach?What I've done is:
App
as:Layout
as:With the above approach I had to:
pattern
for theOrders
navigation to ensure that for child pages the menu item is still selected/orders/
and render a customizedPageContainer
that sets the title and breadcrumbs (as illustrated in the dynamic routes section ofPageContainer
)I'm not sure if the approach makes sense or if I should have rendered another
Outlet
in theOrders
page or if there's another way that's recommended.I'm also facing other challenges such as the page container toolbar which needs to be different depending on the route. I'm also using path matching and rendering different toolbars based on the path. Is that the recommended approach in such cases?
Beta Was this translation helpful? Give feedback.
All reactions