I am using react-router-dom with typescript. I create a config file like below:
export interface RouteComponent {
path?: string;
element?: React.ComponentType<any>;
children?: RouteComponent[];
}
const routes: RouteComponent[] = [
{
element: MenuLayout,
children: [
{
path: "corp-list",
element: CorpList,
},
{
path: "/corp-list/:id",
element: DetailCorp,
},
],
},
{
children: [
{
path: "auth/login",
element: Login,
},
{
path: "auth/signup",
element: Login,
},
],
},
];
Then, I map it to render routes in App.tsx file
{routes.map((route, index) => (
<Route
path={route.path as string}
element={route.element}
/>
))}
It shows an error of type which the element in Route component take children with type of ReactNode, not the React.Component as above. But when I try to declare element in config routes with type of ReactNode, like :
{ path: "corp-list", element: <CorpList /> },
it yells "CorpList refers to a value, but is being used as a type here".
So, how to fix that? And, how do you config route in react-router-dom v6, any suggestion?