I am having a issues when it comes to using the React Router V6. Basically I am trying to map throughout the file which contains the routes (paths, components etc..). The issue I am having is that I am trying to map those routes inside another route because I am using a layout (Have to use that layout since 2 routes do not that layout so that is why). Everything works when I am mapping the <Route/> component since that component is from react-router-dom, but when I am using the helper component called RouteMapper this is the problem I encounter.
File with routes
import { Home, About, Profile} from "../../pages";
export const generalRoutes = [
{
path: "/",
exact: true,
component: <Home />,
},
{
path: "/about",
exact: true,
component: <About/>,
},
{
path: "/profile",
exact: true,
component: <Profile />,
},
];
RouteMapper.jsx
import React from "react";
import { Route } from "react-router-dom";
const RouteMapper = ({ route }) => {
return (
<Route path={route.path} element={route.component} exact={route.exact} />
);
};
export default RouteMapper;
General.jsx
const General = () => {
return (
<>
<Routes>
<Route path="/" element={<Layout />}>
{generalRoutes?.map((route, index) => {
return <RouteMapper route={route} key={index} />;
})}
</Route>
</Routes>
</>
);
};
export default General;
Here I am getting an error. I am using the helper component since I will also implement authentication so it would be much easier for me to implement it this way.