Angular guards related with the environment module.
These guards allow you to manage the load of a route based on the existence or not of certain properties.
Prevent path to be activated if required environment properties doesn't exist.
Below are examples of use cases.
All properties can be overriden using Route Data under the canActivateEnvironment property.
canActivateEnvironment
@Injectable()export class UsernameCanActivateEnvironment extends CanActivateEnvironment { protected override readonly properties: AtLeastOne<Path> = ['user.username']; protected override readonly dueTime = 5000; constructor(protected override readonly router: Router, protected override readonly query: EnvironmentQuery) { super(router, query); }}@NgModule({ imports: [ RouterModule.forRoot([ { path: 'path', component: HomeComponent, canActivate: [UsernameCanActivateEnvironment] } ]), EnvironmentModule.forRoot(); ], providers: [UsernameCanActivateEnvironment]})class AppModule {}
@NgModule({ imports: [ RouterModule.forRoot([ { path: 'path', component: HomeComponent, data: { canActivateEnvironment: { properties: ['user.username'], dueTime: 5000 } } canActivate: [CanActivateEnvironment] } ]), EnvironmentModule.forRoot(); ], providers: [CanActivateEnvironment]})class AppModule {}
Generated using TypeDoc
Angular Environment Guards
These guards allow you to manage the load of a route based on the existence or not of certain properties.
CanActivateEnvironment
Prevent path to be activated if required environment properties doesn't exist.
Use cases
Below are examples of use cases.
Table of Contents
Extending CanActivateEnvironment
All properties can be overriden using Route Data under the
canActivateEnvironment
property.Using Route Data