I have a /register
page that uses react-router
to send the user to /login
if they successfully create an account:
if(redirect) {
return <Navigate to={'/login'} />
}
I want this specific redirection to result in an alert message appearing on the subsequent /login
screen. I was able to achieve this through the use of state
and useLocation
, however this made the /login
page break anytime it was accessed via any method that wasn’t the Nagivate component on /register
because the state would be undefined. How can I pass some kind of data to the next page while allowing it render without that data?
I have tried using state
to pass a value to the next page:
if(redirect) {
return <Navigate to={'/login'} state={{ fromRegister: true }} />
}
…but as I’ve already mentioned trying to access /login
from anywhere else resulted in an error due to state
being undefined.