mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 11:44:05 +08:00
Functional guards and resolvers were introduced in the Angular router in v14.2. This commit adds the ability to generate functional router guards by specifying `--guardType` instead of `--implements`. These guards are also accompanied by a test that includes a helper function for executing the guard in the `TestBed` environment so that any `inject` calls in the guard will work properly. Functional resolvers are generated by adding the `--functional` flag.
18 lines
606 B
TypeScript
18 lines
606 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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
|
|
*/
|
|
|
|
import { Rule } from '@angular-devkit/schematics';
|
|
import { generateFromFiles } from '../utility/generate-from-files';
|
|
import { Schema } from './schema';
|
|
|
|
export default function (options: Schema): Rule {
|
|
return options.functional
|
|
? generateFromFiles({ ...options, templateFilesDirectory: './functional-files' })
|
|
: generateFromFiles({ ...options, templateFilesDirectory: './class-files' });
|
|
}
|