Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to navigate to dashboard page after successful login from Azure AD. However, only the address bar value is getting changed and the actual page is not coming.

Here is my code snippet.

import { useNavigate } from 'react-router-dom';
 import { useMsal, useIsAuthenticated } from "@azure/msal-react";

 const { instance } = useMsal();
 const navigate = useNavigate()

const onSubmit = async () => {
    try {

      const response = await instance.loginPopup(loginRequest);
      
      if(response){
        navigate('dashboard/app')
      }
      
    } catch (error) {
      console.error(error);
      
    }
  };

The address bar is only getting changed to 'dashboard/app' and the page is not coming.

I have tried by removing the async as well, however, it didn't work.

Any help on this please...

I need to navigate to the actual page.

What I have tried:

I have tried by removing async.

As tried using useEffect() hook.
useEffect(() => {
   if(isAuthenticated){
     // navigate('dashboard/app');
     setTimeout(() => navigate('dashboard/app'), 1500);

   }
 },[isAuthenticated]);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900