Change component at the end of function Angular

How can I change to the restricted-page component after completion of the login() function which is a redirect to microsoft log in?

public-page.component.ts

  login() {
  this.msalService.loginRedirect();
  //switch to restricted-page here.
  }

app-routing.module.ts:

    const routes: Routes = [{
  path: 'public-page', component: PublicPageComponent
}, {
  path: 'restricted-page', component: RestrictedPageComponent, canActivate: [MaslGuard]
}, {
  path: '', redirectTo:'public-page', pathMatch:'full',
}];

>Solution :

in login function you have to add:

if (login successfull){
this.router.navigate(['/restricted-page'])
 }

Leave a Reply