In angular2/4 you could inject into a component an instance of ActivatedRoute
, transform it to string with toString()
and check the value of it. For example
@Component()
export class TestComponent{
constructor(private _route: ActivatedRoute){
let link = _route.toString();
console.log(link.contains('ask'));
}
}
Note that this method will return a string with the form Route(url:'${url}', path:'${matched}')
If you want to traverse the singular elements that compose that link, you can navigate up to the root using the parent attribute of the instance.
More info in the following link
Another option would be to directly inject the Router into the component, what will directly allow you to get the current url:
@Component()
export class TestComponent{
constructor(private _router: Router){
let link = _router.url();
console.log(link.contains('ask'));
}
}