Angular 2激活路线

前端之家收集整理的这篇文章主要介绍了Angular 2激活路线前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
也许我错过了什么?

在Angular 2组件中,我只是想获得完整的激活路径.

我不想使用location.href.

我的构造函数如下:

constructor(private route: ActivatedRoute) {}

在ngOnInit()中我试过:

this.route.data.url

this.route.snapshot

都没有工作.

任何帮助都非常感谢.

解决方法

您不需要使用ActivatedRoute,您需要使用 Router以字符串形式查询当前URL:

constructor(r: Router) {
   console.log(r.url);
}

猜你在找的Angularjs相关文章