获取不带参数的当前路由 [英] Get current route without parameters

查看:32
本文介绍了获取不带参数的当前路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Angular 2 中获取没有参数的当前路线,我找到了一种使用参数获取当前路线的方法,如下所示:

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

然后拆分:

 this.router.url.split(';')[0]

但这看起来是一种解决方法,我认为应该有更好的方法吗?

But this looks as workaround, I think there should be better way?

推荐答案

要在没有查询参数的情况下获取当前路由,可以使用下面提到的单行:

To get current route without query parameters, you can use below mentioned single line:

this.router.url.split('?')[0] 

这篇关于获取不带参数的当前路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆