Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49293

Ionic 4 Angular 9 how to bypass particular route in the guard?

$
0
0

I have a guard that redirects the user to tabs page if user has been authenticated else redirects to home (login) page.

Now on a particular operation, my backend express server redirects the user to order-success page. But logic in the guard doesn’t allow the user to be redirected to order-success page instead user gets redirected to tabs page

So how to bypass this url in the guard so that user will go to order-success page

Thank you in advance

auth.guard.ts

export class AuthGuard implements CanActivate   {
  
  constructor(public auth: AuthenticationService, public router : Router,) {}

  async canActivate(): Promise<boolean> {

    let auth = await this.auth.isAuthenticated() // returns true if user is authenticated else false
    if(auth) {
      return true;
    }
    else {
      this.router.navigate(['home'])
      return false;
    }
  }
}

app-routing.module.ts

{ path: '', redirectTo: 'tabs', pathMatch: 'full' },

{
    path: 'tabs', canActivate: [AuthGuard],
    loadChildren: () => import('./pages/tabbar/tabbar.module').then( m => m.TabbarPageModule)
  },

  {
    path: 'order-success',
    loadChildren: () => import('./pages/order-success/order-success.module').then(m => m.OrderSuccessPageModule)
  },

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 49293

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>