0
votes

Is it possible to pass the URL of the route which is clicked when router deactivate event is fired? I have the deactivate gaurd something like this

import { Injectable }    from '@angular/core';
import { CanDeactivate}  from '@angular/router';
import { Observable }    from 'rxjs/Observable';
export interface CanComponentDeactivate {
 canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
@Injectable()
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
constructor(public activeroute:ActivatedRoute){

}
canDeactivate(component: CanComponentDeactivate) {
return component.canDeactivate ? component.canDeactivate(URL) : true;
}
}

And the deactivate event in my component as below canDeactivate(Url:any) { console.log(Url); return false; } I have made a plunker demo here http://plnkr.co/edit/0zLwIoUK7hxm5qZWzsye?p=preview where i am able to get the url of link clicked but it is showing type errors like Property _futureSnapShot Doesnot exist on type ActivatedRoute.Is there any good practices to get the url of the route which is clicked when router deactivate event is fired.

1

1 Answers

0
votes

I think you could use router.events by injecting router: Router in the constructor.

router.events.subscribe((val) => {
    console.log(val);         
});

val will include the url of the route.

Hope this helps.