@ogebman wrote:
Hi, I just created a new ionic project with Starter template tabs, then i want to authenticate only in tab 3, but when I declare
canActivate: [AuthGuardService]
on routes tabs, I can’t access tabs 3 if auth value is false. because other tabs can be accessed without requiring authentication.
this is my codetabs-routing.module.ts
const routes: Routes = [ { path: 'tabs', component: TabsPage, children: [ { path: 'tab1', children: [ { path: '', loadChildren: () => import('../tab1/tab1.module').then(m => m.Tab1PageModule) } ] }, { path: 'tab2', children: [ { path: '', loadChildren: () => import('../tab2/tab2.module').then(m => m.Tab2PageModule) } ] }, { path: 'tab3', canActivate: [AuthGuardService], /* <-- check auth */ children: [ { path: '', loadChildren: () => import('../tab3/tab3.module').then(m => m.Tab3PageModule) } ] }, { path: 'tab4', children: [ { path: '', loadChildren: () => import('../tab4/tab4.module').then(m => m.Tab4PageModule) } ] }, { path: '', redirectTo: '/tabs/tab1', pathMatch: 'full' } ] }, { path: '', redirectTo: '/tabs/tab1', pathMatch: 'full' } ];
auth-guard.service.ts
export class AuthGuardService implements CanActivate{ constructor( private authService: AuthenticationService, ) { } canActivate(): boolean{ return this.authService.isAuthenticated(); } }
Posts: 1
Participants: 1