// read location and supply in requireAuth let location = useLocation() ;<Navigate to='/login' state={{ from: location }} replace /> // use navigate in login to redirect after login let navigate = useNavigate() let from = location.state?.from?.pathname || '/' navigate(from, { replace: true })