czetsuya
czetsuya

Reputation: 5063

How to add CanActivate and loadChildren in the same route

I want to lazy load my module but at the same time protect it using canActivate. I tried:

{ path: 'dashboard/vendor', canActivate: AuthGuard, loadChildren: 'app/module/dashboard/vendor/vendor.module#VendorModule' }

Note that I didn't use children as I have defined the vendor routes in vendor-routing.module using RouterModule.forChild.

But it doesn't work. Any recommendations?

Upvotes: 10

Views: 9696

Answers (1)

alexKhymenko
alexKhymenko

Reputation: 5598

You should use canLoad not canActivate, so if condition is not met it will not load your LazyModule.

{ path: 'dashboard/vendor', canLoad: [AuthGuard], loadChildren: 'app/module/dashboard/vendor/vendor.module#VendorModule' }

Upvotes: 11

Related Questions