New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`canActivate` in guard does not contain `UrlTree` (since Angular 7.1.0) #13390

Closed
d-koppenhagen opened this Issue Jan 9, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@d-koppenhagen
Copy link

d-koppenhagen commented Jan 9, 2019

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [x] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

  • macOS Mojave
  • Node Version: v.10.14.0
  • npm Version: 6.4.1
  • Angular CLI Version: 7.2.1

Repro steps

  • Run:
ng g guard my-example
CREATE src/app/my-example.guard.spec.ts (377 bytes)
CREATE src/app/my-example.guard.ts (419 bytes)
  • open generated my-example.guard.ts, it contains:
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class MyExampleGuard implements CanActivate {
  canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
    return true;
  }
}

The log given by the failure

There is no error given and nothing fails

Desired functionality

As written in the Docs, the content should look like that and contain UrlTree in methods signature:

import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class MyExampleGuard implements CanActivate {
  canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree {
    return true;
  }
}

Mention any other details that might be useful

See: https://angular.io/api/router/CanActivate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment