-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(@schematics/angular): Use MaybeAsync and GuardResult types t…
…o reduce boilerplate This refactor uses new types in the Router to reduce boilerplate. (cherry picked from commit d05f78b)
- Loading branch information
Showing
3 changed files
with
11 additions
and
11 deletions.
There are no files selected for viewing
9 changes: 4 additions & 5 deletions
9
packages/schematics/angular/guard/implements-files/__name@dasherize__.guard.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { <%= routerImports %> } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class <%= classify(name) %>Guard implements <%= implementations %> { | ||
<% if (implements.includes('CanActivate')) { %>canActivate( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
state: RouterStateSnapshot): MaybeAsync<GuardResult> { | ||
return true; | ||
} | ||
<% } %><% if (implements.includes('CanActivateChild')) { %>canActivateChild( | ||
childRoute: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
state: RouterStateSnapshot): MaybeAsync<GuardResult> { | ||
return true; | ||
} | ||
<% } %><% if (implements.includes('CanDeactivate')) { %>canDeactivate( | ||
component: unknown, | ||
currentRoute: ActivatedRouteSnapshot, | ||
currentState: RouterStateSnapshot, | ||
nextState?: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
nextState?: RouterStateSnapshot): MaybeAsync<GuardResult> { | ||
return true; | ||
} | ||
<% } %><% if (implements.includes('CanMatch')) { %>canMatch( | ||
route: Route, | ||
segments: UrlSegment[]): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
segments: UrlSegment[]): MaybeAsync<GuardResult> { | ||
return true; | ||
}<% } %> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters