如何获得当前路线

如何获得当前路线

问题描述:

当前文档仅讨论获取路径参数,而不是实际的路径段.

The current docs only talk about getting route params, not the actual route segments.

例如,如果我想找到当前路线的父级,那怎么可能?

For example, if i want to find the parent of current route, how is that possible?

角度RC4:

您可以从@angular/router

然后注入:

constructor(private router: Router ) {

}

然后将其称为URL参数:

Then call it's URL parameter:

console.log(this.router.url); //  /routename