Hi folks,
here is my sample code as below:    
    
*In AuthGuard.component:*

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    return this.checkLoggedIn(state.url);
}

checkLoggedIn(url: string) {
    if (this.authService.isLoggedIn()) {
        return true;
    }
    this.router.navigate(['/login']);
    return false;
}

*In auth.service:*

isLoggedIn() {
    this.currentUser = localStorage.getItem("sessionUsername");
    this.currentRole = localStorage.getItem("role");
    
    if (this.currentUser && this.currentRole) {
        return true;
    } else {
        return false;
    }
   }

*In app-rotuing:*

const ROUTES = [
    {path: 'Home', component: HomeComponent, canActivate: [AuthGuard],
        children: [
            { path: 'child1', component: UserVehicleDetailsComponent, 
canActivate: [AuthGuard] }, //Admin
            { path: 'child2', component: UserVehicleArchiveComponent, 
canActivate: [AuthGuard] }, //Admin
            { path: 'child3', component: UserFormVehicleComponent, 
canActivate: [AuthGuard] },    //Admin or NonAdmin
            { path: 'child4', component: ToBeInvestigatedComponent, 
canActivate: [AuthGuard] },   //Admin or NonAdmin
        ]
    }];


e.g 
if logged User is sudent1 and role is NonAdmin then should not allow to:
localhost:8000/Home/child1 and 
localhost:8000/Home/child2

How do i do it? Any idea?

I am waiting for your response.

Thanks in advance :)  

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to