How can I get the route which the user is trying to open within an canActivate guard in angular 2?
How can I make the guard watch for every route parameter change eg. a change of the id within the route?
import { Injectable } from '@angular/core';
import {Observable, Observer, Subject} from "rxjs/Rx";
@Injectable()
export class RightsGuard implements CanActivate {
constructor(
private router: Router,
private route: ActivatedRoute
// private state: RouterStateSnapshot
) { }
canActivate(): Observable<boolean> | boolean {
var targetUrl = ???
// var targetUrl = this.router.url // is showing previous url?
return true;
}
}
Suggested answer in Angular 2 get current route in guard using private state: RouterStateSnapshot
and then this.route.url
does not work for me, since it throws an DI error:
Error: Uncaught (in promise): Error: DI Error
Error: DI Error