Skip to content

Wrong parameter name of CanActivate guard. #18601

@wellwind

Description

@wellwind

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Description

According to the document of CanActivate interface, the parameters of canActivate is

canActivate(
  route: ActivatedRouteSnapshot, 
  state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree

But the parameters of the generated guard file is

canActivate(
  next: ActivatedRouteSnapshot, 
//~~~~
//should be "route"
  state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
  return true;
}

🔬 Minimal Reproduction

  1. ng new guard-impl-demo --defaults
  2. cd guard-impl-demo
  3. ng generate guard auth --implements CanActivate

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 10.0.7
Node: 12.13.0
OS: win32 x64

Angular: 10.0.11
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.7
@angular-devkit/build-angular     0.1000.7
@angular-devkit/build-optimizer   0.1000.7
@angular-devkit/build-webpack     0.1000.7
@angular-devkit/core              10.0.7
@angular-devkit/schematics        10.0.7
@angular/cli                      10.0.7
@ngtools/webpack                  10.0.7
@schematics/angular               10.0.7
@schematics/update                0.1000.7
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: @schematics/angularfreq1: lowOnly reported by a handful of users who observe it rarelygood first issueLabel noting a good first issue to be worked on by a community memberhelp wantedLabel noting an issue which the team is looking for contribution from the community to fixseverity1: confusingtype: bug/fix

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions