I want to migrate from React Router V5 to V6, I used to map trough private routes and have a HOC that renders each private page components. I'm not sure how do it in same type of fashion for V6.
Here's how my Root component looked like:
const WrappedComponent = () => (
<Switch>
<Route exact path="/">
<Redirect to={routes.LOGIN} />
</Route>
<Route exact path={routes.LOGIN} component={Login} />
{privateRoutes.map((route) => (
<PrivateRoute
exact
component={route.component}
path={route.path}
key={route.path}
/>
))}
</Switch>
);
And here's how my PrivateRoute
component looks like:
const PrivateRoute = ({ component: Component, ...props }) => {
const { loggedIn } = useSelector(({ auth }) => auth);
return (
<Route
render={(routerProps) =>
loggedIn ? (
<Component {...props} {...routerProps} />
) : (
<Redirect to={{ pathname: routes.LOGIN }} push />
)
}
/>
);
};
What is the way to map trough private routes and render them in React Router V6?