Sunday, October 29, 2017

There was an Angular routing talk by John Niedzwiecki at AngularMix.

He recommends using CanActive with a role guard to safeguard if someone has permissions to visit a route. Also, I was surprised to learn that the lazy loading of an app may selectively not lazy load content that realistically the immediate user has no way of seeing because they are walled off from it by way of permissions restrictions and this all ties into the guards.

The code shown in the image is:

import { HomeComponent } from './home/home.component';
import { ResortDetailsComponent } from './resort-details/resort-details.component';
import { ResortResolverService } from './shared/resort-resolver.service';
import { RoleGuard } from './shared/role-guard.service';
import { SitemapComponent } from './sitemap/sitemap.component';
import { UserProfileComponent } from './user-profile/user-profile.component';
 
const routes: Routes = [
   { path '', redirectTo: 'home', pathMatch: 'full' },
   {
      path: 'admin',
      component: AdminComponent,
      canActivate: [RoleGuard],
      data: { roles: ['ADMIN', 'SUPER_ADMIN'] }
   },
   { path: 'error', component: ErrorComponent},
   { path: 'home', component: HomeComponent },
   {
      path: 'resort/:resortId/details',
      component: ResortDetailsComponent,
      canDeactivate: [ CanDeactivateGuard ],
      resolve : {
         resortName: ResortResolverService
      }
   },
   { path: 'sitemap', component: SitemapComponent },
   {

No comments:

Post a Comment