Home > Mobile >  Landing page URL should be "/home" instead of "/"
Landing page URL should be "/home" instead of "/"

Time:02-14

Current landing page URL after login - 'www.website.com'. But I want it to be redirected to "www.website.com/home" upon login. So it has to be redirected to home component.

I am using MSAL for Azure AD authentication. May I know where I could use react router here.

export default class App extends Component {

    var user = authProvider.getAccount();
    if (user) {
        this.getMyProfile();
    }
}

async login() {
    await authProvider.login();
    await this.getMyProfile();
}


 return (
        <div>        
         <nav                                             
                 <a>
                    <AzureAD provider={authProvider} forceLogin={true}>
                        {
                            ({ login, logout, authenticationState, error, accountInfo }) => {
                                switch (authenticationState) {
                                   
                                    case AuthenticationState.Unauthenticated:
                                       
                                               
                                                <p>
                                                    <button className="badge badge-secondary"
                                                        id="signInOut"
                                                        onClick={login}>Sign In</button>
                                                </p>
                                            </div>
                                        );
                                    case AuthenticationState.InProgress:
                                        return (<p>Authenticating...</p>);
                                }
                            }
                        }
                    </AzureAD>

                </a>
            </nav>

CodePudding user response:

Maybe you can just change your path from "/" to "/home"?

CodePudding user response:

If you have a solution to check if the user is log you can do that

<Route exact path="/">
  {loggedIn ? <Redirect to="/home" /> : <LoginPage />}
</Route>

If not, you need to redirect to '/home' after login directly after the function of log (in the .then() if you'r loginAction is promise or just after login function). With React Router v5 : history.push('/home') With React Router v6 : navigate('/home') See the doc of React Router if you need more explanation.

CodePudding user response:

you could simply redirect "/" to "/home"

  • Related