[英]How to get the path name of the current route in AngularJS?
我正在寻找一种方法来检索当前路由的路径名,因为我在$routeProvider
定义了它,即/customer/:id
。
$location.path()
返回路径/customer/1
,但不返回路径名称/customer/:id
。
我发现$route.current.$$route.originalPath
返回的正是我需要的。 但是,我非常希望不必依赖私有方法。
是否有$route.current.$$route.originalPath
的公共等价物?
不确定您是否找到了另一种方法来做到这一点,并且在我调试一些路由问题时碰巧遇到了这个问题 -
AFAIK 获得您所需要的唯一方法是使用:
$route.current.$$route.originalPath
处理此问题的另一种方法是使用诸如 routeChangeStart/routeChangeSuccess 之类的广播事件来正式知道哪条路由已解决。
$rootScope.$on('$routeChangeSuccess', function (event, next, prev) {
console.log(next.$$route.originalPath);
});
尝试
$route.current.originalPath
您可以使用
$state.$current.url.sourcePath
但它也有点hacky :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.