Can't access a react protected route using URL

Hi,
yes I am redirected to ‘/user’ after I login.
I added {replace: true} in theonRedirectCallback props like this so the root path doesn’t stack anymore:

const Auth0ProviderWithRedirectCallback = ({ children, ...props }) => {
  const navigate = useNavigate();
  const onRedirectCallback = (appState) => {
    navigate(appState?.returnTo || window.location.pathname, { replace: true }); // here
  };
  return (
    <Auth0Provider onRedirectCallback={onRedirectCallback} {...props}>
      {children}
    </Auth0Provider>
  );
};

Now, after logging in, the history stack looks like this :

  • 1 - Initial route from where I want to access /user
  • 2 - after login : /user path
  • 3 - /user path again and it

If I click the arrow to go back to the first /user path in history, it renders the loading page and doesn’t no redirect.

1 Like