Answer the question
In order to leave comments, you need to log in
React-router Redirect previous location ??
There is a redirect from the product page for an unlogged user to the login page, I need to return it to the product page after login, I need props from the previous location so that if this is the location of the product, then do history.goBack() otherwise history.push(home). I know you can do this in links, but I didn’t find it in the redirect.
Answer the question
In order to leave comments, you need to log in
Redirect:
<Redirect
to={{
pathname: '/login',
state: { referrer: props.history.location.pathname }, // или `/products/${slug}`
}}
/>
class Login extends React.Component {
onLoginSuccess() {
const { history } = this.props;
const { state } = history.location;
const location = (state && state.referrer) || '/';
history.push(location);
}
/* ... *.
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question