2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2018-02-27 17:06:06 -05:00
|
|
|
import {Observable} from 'rxjs';
|
2016-07-26 14:39:02 -07:00
|
|
|
|
|
|
|
import {Route} from './config';
|
2016-06-02 15:29:15 -07:00
|
|
|
import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
|
2018-10-03 15:35:13 -07:00
|
|
|
import {UrlSegment, UrlTree} from './url_tree';
|
2016-06-02 15:29:15 -07:00
|
|
|
|
2016-07-26 14:39:02 -07:00
|
|
|
|
2016-06-02 15:29:15 -07:00
|
|
|
/**
|
2018-04-05 11:38:57 +01:00
|
|
|
* @description
|
2016-06-28 14:49:29 -07:00
|
|
|
*
|
2018-04-05 11:51:21 +01:00
|
|
|
* Interface that a class can implement to be a guard deciding if a route can be activated.
|
2018-10-17 09:30:45 -07:00
|
|
|
* If all guards return `true`, navigation will continue. If any guard returns `false`,
|
|
|
|
* navigation will be cancelled. If any guard returns a `UrlTree`, current navigation will
|
|
|
|
* be cancelled and a new navigation will be kicked off to the `UrlTree` returned from the
|
|
|
|
* guard.
|
2018-04-05 11:51:21 +01:00
|
|
|
*
|
2016-06-28 14:49:29 -07:00
|
|
|
* ```
|
2016-08-30 15:57:24 -07:00
|
|
|
* class UserToken {}
|
|
|
|
* class Permissions {
|
|
|
|
* canActivate(user: UserToken, id: string): boolean {
|
|
|
|
* return true;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-07-13 16:27:32 +02:00
|
|
|
* @Injectable()
|
2016-06-28 14:49:29 -07:00
|
|
|
* class CanActivateTeam implements CanActivate {
|
|
|
|
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* canActivate(
|
|
|
|
* route: ActivatedRouteSnapshot,
|
|
|
|
* state: RouterStateSnapshot
|
2018-10-17 09:30:45 -07:00
|
|
|
* ): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree {
|
2016-08-19 17:48:09 -05:00
|
|
|
* return this.permissions.canActivate(this.currentUser, route.params.id);
|
2016-06-28 14:49:29 -07:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
|
|
|
* path: 'team/:id',
|
2019-03-04 14:57:31 +01:00
|
|
|
* component: TeamComponent,
|
2016-08-19 17:48:09 -05:00
|
|
|
* canActivate: [CanActivateTeam]
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
2016-08-30 15:57:24 -07:00
|
|
|
* providers: [CanActivateTeam, UserToken, Permissions]
|
2016-08-19 17:48:09 -05:00
|
|
|
* })
|
2016-08-30 15:57:24 -07:00
|
|
|
* class AppModule {}
|
2016-06-28 14:49:29 -07:00
|
|
|
* ```
|
|
|
|
*
|
2017-02-16 10:26:53 -08:00
|
|
|
* You can alternatively provide a function with the `canActivate` signature:
|
2016-06-28 14:49:29 -07:00
|
|
|
*
|
|
|
|
* ```
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
|
|
|
* path: 'team/:id',
|
2019-03-04 14:57:31 +01:00
|
|
|
* component: TeamComponent,
|
2016-08-19 17:48:09 -05:00
|
|
|
* canActivate: ['canActivateTeam']
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
|
|
|
* providers: [
|
|
|
|
* {
|
|
|
|
* provide: 'canActivateTeam',
|
|
|
|
* useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => true
|
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* })
|
2016-08-30 15:57:24 -07:00
|
|
|
* class AppModule {}
|
2016-06-28 14:49:29 -07:00
|
|
|
* ```
|
|
|
|
*
|
2018-10-19 18:25:11 +01:00
|
|
|
* @publicApi
|
2016-06-02 15:29:15 -07:00
|
|
|
*/
|
|
|
|
export interface CanActivate {
|
2016-06-08 11:13:41 -07:00
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
|
2018-10-03 15:35:13 -07:00
|
|
|
Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree;
|
2016-07-13 15:15:20 -07:00
|
|
|
}
|
|
|
|
|
2018-10-03 15:35:13 -07:00
|
|
|
export type CanActivateFn = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) =>
|
2020-04-13 16:40:21 -07:00
|
|
|
Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree;
|
2018-10-03 15:35:13 -07:00
|
|
|
|
2016-07-13 15:15:20 -07:00
|
|
|
/**
|
2018-04-05 11:38:57 +01:00
|
|
|
* @description
|
2016-07-13 15:15:20 -07:00
|
|
|
*
|
2018-04-05 11:51:21 +01:00
|
|
|
* Interface that a class can implement to be a guard deciding if a child route can be activated.
|
2018-10-17 09:30:45 -07:00
|
|
|
* If all guards return `true`, navigation will continue. If any guard returns `false`,
|
|
|
|
* navigation will be cancelled. If any guard returns a `UrlTree`, current navigation will
|
|
|
|
* be cancelled and a new navigation will be kicked off to the `UrlTree` returned from the
|
|
|
|
* guard.
|
2018-11-01 11:36:40 +00:00
|
|
|
*
|
2016-07-13 15:15:20 -07:00
|
|
|
* ```
|
2016-08-30 15:57:24 -07:00
|
|
|
* class UserToken {}
|
|
|
|
* class Permissions {
|
|
|
|
* canActivate(user: UserToken, id: string): boolean {
|
|
|
|
* return true;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-07-13 15:15:20 -07:00
|
|
|
* @Injectable()
|
2016-10-11 15:47:57 -07:00
|
|
|
* class CanActivateTeam implements CanActivateChild {
|
2016-07-13 15:15:20 -07:00
|
|
|
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* canActivateChild(
|
|
|
|
* route: ActivatedRouteSnapshot,
|
|
|
|
* state: RouterStateSnapshot
|
2018-10-17 09:30:45 -07:00
|
|
|
* ): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree {
|
2016-07-26 14:39:02 -07:00
|
|
|
* return this.permissions.canActivate(this.currentUser, route.params.id);
|
2016-07-13 15:15:20 -07:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
|
|
|
* path: 'root',
|
|
|
|
* canActivateChild: [CanActivateTeam],
|
|
|
|
* children: [
|
|
|
|
* {
|
|
|
|
* path: 'team/:id',
|
2019-03-04 14:57:31 +01:00
|
|
|
* component: TeamComponent
|
2016-08-19 17:48:09 -05:00
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
2016-08-30 15:57:24 -07:00
|
|
|
* providers: [CanActivateTeam, UserToken, Permissions]
|
2016-08-19 17:48:09 -05:00
|
|
|
* })
|
2016-08-30 15:57:24 -07:00
|
|
|
* class AppModule {}
|
2016-07-13 15:15:20 -07:00
|
|
|
* ```
|
|
|
|
*
|
2017-02-16 10:26:53 -08:00
|
|
|
* You can alternatively provide a function with the `canActivateChild` signature:
|
2016-07-13 15:15:20 -07:00
|
|
|
*
|
|
|
|
* ```
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
|
|
|
* path: 'root',
|
|
|
|
* canActivateChild: ['canActivateTeam'],
|
|
|
|
* children: [
|
|
|
|
* {
|
|
|
|
* path: 'team/:id',
|
2019-03-04 14:57:31 +01:00
|
|
|
* component: TeamComponent
|
2016-08-19 17:48:09 -05:00
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
|
|
|
* providers: [
|
2016-07-13 15:15:20 -07:00
|
|
|
* {
|
2016-08-19 17:48:09 -05:00
|
|
|
* provide: 'canActivateTeam',
|
|
|
|
* useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => true
|
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* })
|
2016-08-30 15:57:24 -07:00
|
|
|
* class AppModule {}
|
2016-07-13 15:15:20 -07:00
|
|
|
* ```
|
|
|
|
*
|
2018-10-19 18:25:11 +01:00
|
|
|
* @publicApi
|
2016-07-13 15:15:20 -07:00
|
|
|
*/
|
|
|
|
export interface CanActivateChild {
|
|
|
|
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot):
|
2018-10-03 15:35:13 -07:00
|
|
|
Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree;
|
2016-06-02 15:29:15 -07:00
|
|
|
}
|
|
|
|
|
2018-10-03 15:35:13 -07:00
|
|
|
export type CanActivateChildFn = (childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot) =>
|
2020-04-13 16:40:21 -07:00
|
|
|
Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree;
|
2018-10-03 15:35:13 -07:00
|
|
|
|
2016-06-02 15:29:15 -07:00
|
|
|
/**
|
2018-04-05 11:38:57 +01:00
|
|
|
* @description
|
2016-06-28 14:49:29 -07:00
|
|
|
*
|
2018-04-05 11:51:21 +01:00
|
|
|
* Interface that a class can implement to be a guard deciding if a route can be deactivated.
|
2018-10-17 09:30:45 -07:00
|
|
|
* If all guards return `true`, navigation will continue. If any guard returns `false`,
|
|
|
|
* navigation will be cancelled. If any guard returns a `UrlTree`, current navigation will
|
|
|
|
* be cancelled and a new navigation will be kicked off to the `UrlTree` returned from the
|
|
|
|
* guard.
|
2018-11-01 11:36:40 +00:00
|
|
|
*
|
2016-06-28 14:49:29 -07:00
|
|
|
* ```
|
2016-08-30 15:57:24 -07:00
|
|
|
* class UserToken {}
|
|
|
|
* class Permissions {
|
|
|
|
* canDeactivate(user: UserToken, id: string): boolean {
|
|
|
|
* return true;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-07-13 16:27:32 +02:00
|
|
|
* @Injectable()
|
2016-08-19 17:48:09 -05:00
|
|
|
* class CanDeactivateTeam implements CanDeactivate<TeamComponent> {
|
2016-06-28 14:49:29 -07:00
|
|
|
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* canDeactivate(
|
|
|
|
* component: TeamComponent,
|
2016-12-28 01:08:06 +03:00
|
|
|
* currentRoute: ActivatedRouteSnapshot,
|
|
|
|
* currentState: RouterStateSnapshot,
|
|
|
|
* nextState: RouterStateSnapshot
|
2018-10-17 09:30:45 -07:00
|
|
|
* ): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree {
|
2016-07-26 14:39:02 -07:00
|
|
|
* return this.permissions.canDeactivate(this.currentUser, route.params.id);
|
2016-06-28 14:49:29 -07:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
|
|
|
* path: 'team/:id',
|
2019-03-04 14:57:31 +01:00
|
|
|
* component: TeamComponent,
|
2016-08-19 17:48:09 -05:00
|
|
|
* canDeactivate: [CanDeactivateTeam]
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
2016-08-30 15:57:24 -07:00
|
|
|
* providers: [CanDeactivateTeam, UserToken, Permissions]
|
2016-08-19 17:48:09 -05:00
|
|
|
* })
|
2016-08-30 15:57:24 -07:00
|
|
|
* class AppModule {}
|
2016-06-28 14:49:29 -07:00
|
|
|
* ```
|
|
|
|
*
|
2017-02-16 10:26:53 -08:00
|
|
|
* You can alternatively provide a function with the `canDeactivate` signature:
|
2016-06-28 14:49:29 -07:00
|
|
|
*
|
|
|
|
* ```
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
|
|
|
* path: 'team/:id',
|
2019-03-04 14:57:31 +01:00
|
|
|
* component: TeamComponent,
|
2017-01-20 17:19:23 -05:00
|
|
|
* canDeactivate: ['canDeactivateTeam']
|
2016-08-19 17:48:09 -05:00
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
|
|
|
* providers: [
|
|
|
|
* {
|
|
|
|
* provide: 'canDeactivateTeam',
|
2016-12-28 01:08:06 +03:00
|
|
|
* useValue: (component: TeamComponent, currentRoute: ActivatedRouteSnapshot, currentState:
|
|
|
|
* RouterStateSnapshot, nextState: RouterStateSnapshot) => true
|
2016-08-19 17:48:09 -05:00
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* })
|
2016-08-30 15:57:24 -07:00
|
|
|
* class AppModule {}
|
2016-06-28 14:49:29 -07:00
|
|
|
* ```
|
|
|
|
*
|
2018-10-19 18:25:11 +01:00
|
|
|
* @publicApi
|
2016-06-02 15:29:15 -07:00
|
|
|
*/
|
|
|
|
export interface CanDeactivate<T> {
|
2016-12-28 01:08:06 +03:00
|
|
|
canDeactivate(
|
|
|
|
component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot,
|
2018-10-03 15:35:13 -07:00
|
|
|
nextState?: RouterStateSnapshot): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean
|
|
|
|
|UrlTree;
|
2016-06-27 14:00:07 -07:00
|
|
|
}
|
|
|
|
|
2018-10-03 15:35:13 -07:00
|
|
|
export type CanDeactivateFn<T> =
|
|
|
|
(component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot,
|
2018-10-05 11:45:06 -07:00
|
|
|
nextState?: RouterStateSnapshot) =>
|
2020-04-13 16:40:21 -07:00
|
|
|
Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree;
|
2018-10-03 15:35:13 -07:00
|
|
|
|
2016-06-27 12:27:23 -07:00
|
|
|
/**
|
2018-04-05 11:38:57 +01:00
|
|
|
* @description
|
2016-06-28 14:49:29 -07:00
|
|
|
*
|
2019-04-16 10:13:14 -05:00
|
|
|
* Interface that classes can implement to be a data provider.
|
2019-07-23 23:03:46 +02:00
|
|
|
* A data provider class can be used with the router to resolve data during navigation.
|
|
|
|
* The interface defines a `resolve()` method that will be invoked when the navigation starts.
|
|
|
|
* The router will then wait for the data to be resolved before the route is finally activated.
|
2018-04-05 11:51:21 +01:00
|
|
|
*
|
2016-06-28 14:49:29 -07:00
|
|
|
* ```
|
2019-07-23 23:03:46 +02:00
|
|
|
* @Injectable({ providedIn: 'root' })
|
|
|
|
* export class HeroResolver implements Resolve<Hero> {
|
|
|
|
* constructor(private service: HeroService) {}
|
2016-06-28 14:49:29 -07:00
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* resolve(
|
|
|
|
* route: ActivatedRouteSnapshot,
|
|
|
|
* state: RouterStateSnapshot
|
|
|
|
* ): Observable<any>|Promise<any>|any {
|
2019-07-23 23:03:46 +02:00
|
|
|
* return this.service.getHero(route.paramMap.get('id'));
|
2016-06-28 14:49:29 -07:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
2019-07-23 23:03:46 +02:00
|
|
|
* path: 'detail/:id',
|
|
|
|
* component: HeroDetailComponent,
|
2016-08-19 17:48:09 -05:00
|
|
|
* resolve: {
|
2019-07-23 23:03:46 +02:00
|
|
|
* hero: HeroResolver
|
2016-08-19 17:48:09 -05:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
2019-07-23 23:03:46 +02:00
|
|
|
* exports: [RouterModule]
|
2016-08-19 17:48:09 -05:00
|
|
|
* })
|
2019-07-23 23:03:46 +02:00
|
|
|
* export class AppRoutingModule {}
|
2016-06-28 14:49:29 -07:00
|
|
|
* ```
|
|
|
|
*
|
2017-02-16 10:26:53 -08:00
|
|
|
* You can alternatively provide a function with the `resolve` signature:
|
2016-06-28 14:49:29 -07:00
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* ```
|
2019-07-23 23:03:46 +02:00
|
|
|
* export const myHero: Hero = {
|
|
|
|
* // ...
|
|
|
|
* }
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
2019-07-23 23:03:46 +02:00
|
|
|
* path: 'detail/:id',
|
|
|
|
* component: HeroComponent,
|
2016-08-19 17:48:09 -05:00
|
|
|
* resolve: {
|
2019-07-23 23:03:46 +02:00
|
|
|
* hero: 'heroResolver'
|
2016-08-19 17:48:09 -05:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
|
|
|
* providers: [
|
|
|
|
* {
|
2019-07-23 23:03:46 +02:00
|
|
|
* provide: 'heroResolver',
|
|
|
|
* useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => myHero
|
2016-08-19 17:48:09 -05:00
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* })
|
2019-07-23 23:03:46 +02:00
|
|
|
* export class AppModule {}
|
2016-08-19 17:48:09 -05:00
|
|
|
* ```
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2018-10-19 18:25:11 +01:00
|
|
|
* @publicApi
|
2016-06-27 12:27:23 -07:00
|
|
|
*/
|
2016-06-27 14:00:07 -07:00
|
|
|
export interface Resolve<T> {
|
2016-12-08 20:24:38 +01:00
|
|
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<T>|Promise<T>|T;
|
2016-06-27 12:27:23 -07:00
|
|
|
}
|
2016-07-26 14:39:02 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-04-05 11:38:57 +01:00
|
|
|
* @description
|
2016-07-26 14:39:02 -07:00
|
|
|
*
|
2019-01-02 15:42:46 -05:00
|
|
|
* Interface that a class can implement to be a guard deciding if children can be loaded.
|
2020-04-13 10:50:44 -07:00
|
|
|
* If all guards return `true`, navigation will continue. If any guard returns `false`,
|
|
|
|
* navigation will be cancelled. If any guard returns a `UrlTree`, current navigation will
|
|
|
|
* be cancelled and a new navigation will be kicked off to the `UrlTree` returned from the
|
|
|
|
* guard.
|
2018-04-05 11:51:21 +01:00
|
|
|
*
|
2016-07-26 14:39:02 -07:00
|
|
|
* ```
|
2016-08-30 15:57:24 -07:00
|
|
|
* class UserToken {}
|
|
|
|
* class Permissions {
|
2017-07-19 20:48:39 +02:00
|
|
|
* canLoadChildren(user: UserToken, id: string, segments: UrlSegment[]): boolean {
|
2016-08-30 15:57:24 -07:00
|
|
|
* return true;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-07-26 14:39:02 -07:00
|
|
|
* @Injectable()
|
2016-08-01 15:48:40 -07:00
|
|
|
* class CanLoadTeamSection implements CanLoad {
|
2016-07-26 14:39:02 -07:00
|
|
|
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
|
|
|
*
|
2017-07-19 20:48:39 +02:00
|
|
|
* canLoad(route: Route, segments: UrlSegment[]): Observable<boolean>|Promise<boolean>|boolean {
|
|
|
|
* return this.permissions.canLoadChildren(this.currentUser, route, segments);
|
2016-07-26 14:39:02 -07:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
|
|
|
* path: 'team/:id',
|
2019-03-04 14:57:31 +01:00
|
|
|
* component: TeamComponent,
|
2016-08-19 17:48:09 -05:00
|
|
|
* loadChildren: 'team.js',
|
|
|
|
* canLoad: [CanLoadTeamSection]
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
2016-08-30 15:57:24 -07:00
|
|
|
* providers: [CanLoadTeamSection, UserToken, Permissions]
|
2016-08-19 17:48:09 -05:00
|
|
|
* })
|
2016-08-30 15:57:24 -07:00
|
|
|
* class AppModule {}
|
2016-07-26 14:39:02 -07:00
|
|
|
* ```
|
|
|
|
*
|
2017-02-16 10:26:53 -08:00
|
|
|
* You can alternatively provide a function with the `canLoad` signature:
|
2016-07-26 14:39:02 -07:00
|
|
|
*
|
|
|
|
* ```
|
2016-08-19 17:48:09 -05:00
|
|
|
* @NgModule({
|
|
|
|
* imports: [
|
|
|
|
* RouterModule.forRoot([
|
|
|
|
* {
|
|
|
|
* path: 'team/:id',
|
2019-03-04 14:57:31 +01:00
|
|
|
* component: TeamComponent,
|
2016-08-19 17:48:09 -05:00
|
|
|
* loadChildren: 'team.js',
|
|
|
|
* canLoad: ['canLoadTeamSection']
|
|
|
|
* }
|
|
|
|
* ])
|
|
|
|
* ],
|
|
|
|
* providers: [
|
|
|
|
* {
|
|
|
|
* provide: 'canLoadTeamSection',
|
2017-07-19 20:48:39 +02:00
|
|
|
* useValue: (route: Route, segments: UrlSegment[]) => true
|
2016-08-19 17:48:09 -05:00
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* })
|
2016-08-30 15:57:24 -07:00
|
|
|
* class AppModule {}
|
2016-07-26 14:39:02 -07:00
|
|
|
* ```
|
|
|
|
*
|
2018-10-19 18:25:11 +01:00
|
|
|
* @publicApi
|
2016-07-26 14:39:02 -07:00
|
|
|
*/
|
2018-10-03 15:35:13 -07:00
|
|
|
export interface CanLoad {
|
2020-04-13 10:50:44 -07:00
|
|
|
canLoad(route: Route, segments: UrlSegment[]):
|
|
|
|
Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree;
|
2018-10-03 15:35:13 -07:00
|
|
|
}
|
2018-10-03 15:32:52 -07:00
|
|
|
|
|
|
|
export type CanLoadFn = (route: Route, segments: UrlSegment[]) =>
|
2020-04-13 10:50:44 -07:00
|
|
|
Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree;
|