Answer the question
In order to leave comments, you need to log in
How to correctly implement Route for this case?
How to redirect (not let go) by url "/auth" ?
There is a "/auth" route that renders a component that has its own routes.
<Route
path={"/auth"}
component={AuthPage}
/>
Answer the question
In order to leave comments, you need to log in
You need to decide on the case when the url /auth
should be resolved by a redirect. For example - when the user is already authorized. Next, you need to create a type wrapper component:
const PublicRoute = ({component: Component, isLogin, ...rest}) => {
return (
<Route {...rest} render={props => (
isLogin ?
<Redirect to="нужный урл" />
: <Component {...props} />
)} />
);
};
<BrowserRouter>
<Switch>
<PublicRoute component={SignIn} isLogin={...} path="/auth" exact />
</Switch>
</BrowserRouter>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question