[angular] How to get current route

short version if you have Router imported then you can simply use some thing like

this.router.url === "/search"

else do the following

1) Import the router

import { Router } from '@angular/router';

2) Declare its entry in constructor

constructor(private router: Router) { }

3) Use its value in your function

yourFunction(){
    if(this.router.url === "/search"){
        //some logic
    }
}

@victor answer helped me, this is the same answer as him but with a little detail, as it might help someone