Get current route without parameters

前端 未结 12 1444
梦如初夏
梦如初夏 2021-01-01 09:08

I need to get my current route without params in Angular 2, I found a way to get the current route with params as follows:

 this.router.url

12条回答
  •  没有蜡笔的小新
    2021-01-01 09:33

    For me, this is the cleanest solution I managed to do. I hope it helps

    import { Router } from '@angular/router';
    
    constructor(private router: Router){}
    
    getUrlWithoutParams(){
       let urlTree = this.router.parseUrl(this.router.url);
       urlTree.queryParams = {}; 
       return urlTree.toString();
    }
    

提交回复
热议问题