I found this interesting piece of code (here) that generates breadcrumbs together with dynamically rendered routes:
routes.ts
{ path: "/home", name: "Home", Component: Home },
{ path: "/dashboard", name: "Dashboard", Component: Dashboard },
{ path: "/all-users", name: "All users", Component: AllUsers },
{ path: "/user/:id", name: "User", Component: User },
{ path: "/all-contracts", name: "All contracts", Component: AllContracts },
{ path: "/login", name: "Login", Component: Login }
];
App.tsx
<Router>
<Switch>
{ routes.map(({ path, Component }, key) => (
<Route
path={path}
key={key}
render={ (props:any) => {
const crumbs = routes
.filter(({ path }) => props.match.path.includes(path))
.map(({ path, ...rest }) => ({
path: Object.keys(props.match.params).length
? Object.keys(props.match.params)
.reduce((path, param) => path.replace(`:${param}`, props.match.params[param]), path )
: path, ...rest }))
return (
<>
<BreadCrumbs crumbs={crumbs} />
<Component {...props} />
</>
);
}}
/>
))}
</Switch>
</Router>
This is react router V5 technology, and I cannot figure out how to translate this in a context with router V6 (+ Typescript!), where Route does not accept a render(props) method...
If anyone can see any clearer in this than me, it would be wonderful : )
Thanks in advance !
