Get current route without parameters

前端 未结 12 1443
梦如初夏
梦如初夏 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:20

    Native javascript will work to split the url into logical parts. Check out the "location" (or window.location) object. For example, using location at the url https://example.com/pathname1/pathname2?queryParam1=1&queryParam2=2 yields

    location.origin === 'https://example.com/pathname1/pathname2'
    location.href === 'https://example.com/pathname1/pathname2?queryParam1=1&queryParam2=2'
    location.pathname === '/pathname1/pathname2'
    location.search === '?queryParam1=1&queryParam2=2'
    

提交回复
热议问题