I need to navigate back to the original requested URL after login.
For example, user enters www.example.com/settings
as user is not authenticated, it will navigate to login page www.example.com/login
.
Once authenticated, it should navigate back to www.example.com/settings
automatically.
My original approach with react-router-dom
v5 is quite simple:
const PrivateRoute = ({ isLoggedIn, component: Component, ...rest }) => {
return (
<Route
{...rest}
render={(props) =>
isLoggedIn? (
<Component {...props} />
) : (
<Redirect
to={{ pathname: `/login/${props.location.search}`, state: { from: props.location } }}
/>
)
}
/>
);
};
<PrivateRoute exact isLoggedIn={isLoggedIn} path="/settings" component={Settings} />
Can some one tell me how to do that in v6? Thanks in advance