You put some state in Navigation props, and on login after submit redirect back, something like this
Navigation
function PrivateRoute() { const location = useLocation() return <Navigation to="/login" state={{ from: location.pathname }} /> } function Login() { const navigate = useNavigate() const location = useLocation() const onSubmit = () => fetch("/api/login").then(() => navigate(location.state.from)) return <form onSubmit={onSubmit} /> }
You mean to prevent before user is clicking a link? 🤔 Didn't quite get what exactly do you mean.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You put some state in
Navigation
props, and on login after submit redirect back, something like thisYou mean to prevent before user is clicking a link? 🤔 Didn't quite get what exactly do you mean.