instead of type everything manually ,I just want to render my routes as an array.
export const routes = [
{
path: "/",
component: Home,
layout: NonAuthLayout,
},
{
path: "/about",
component: About,
layout: NonAuthLayout,
},
];
and in my app.js file, I did something like this:
<BrowserRouter>
<Routes>
{routes.map((route, index) => {
const Component = route.component;
const Layout = route.layout || Fragment;
return (
<Route
key={index}
path={route.path}
element={
<Layout>
<Component />
</Layout>
}
/>
);
})}
</Routes>
</BrowserRouter>
But its giving error , while I tried to execute it.
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
at Routes (http://localhost:3000/static/js/bundle.js:57985:5)
at InnerThemeProvider (http://localhost:3000/static/js/bundle.js:12771:70)
at ThemeProvider (http://localhost:3000/static/js/bundle.js:12462:5)
at ThemeProvider (http://localhost:3000/static/js/bundle.js:12791:5)
at Router (http://localhost:3000/static/js/bundle.js:57918:15)
at BrowserRouter (http://localhost:3000/static/js/bundle.js:56727:5)
at App
at SettingProvider (http://localhost:3000/static/js/bundle.js:174:5)
but but, If I put like this it works:
<Route path="/" element={} />
update- non-auth layout piucture
I think , I did some silly mistake. can someone correct me here?