In react router V5, you can use
history.push('/login?redirect=other_page')
to redirect a user either to '/login', or to '/other_page' (if already logged in )
What is the equivalent in react router V6 with useNavigate ?
navigate('/login?redirect=other_page')
doesn't work as intended.
When the user is logged-in, it returns the path '/login/other_page' instead of '/other_page'.
CodePudding user response:
react-router-dom v6 uses absolute and relative navigation. My guess is that with path '/login?redirect=other_page' the redirect queryString value is "other_page" and you are redirecting there from "/login", i.e. relative from "/login" to "/login/other_path". The difference between absolute and relative navigation is the leading "/" character. Absolute paths start with "/" while relative paths do not.
You could try sending an absolute path '/login?redirect=/other_page'.
navigate('/login?redirect=/other_page');
