Javascript 从ActiveRouteSnapshot获取URL段的角度
我需要从Javascript 从ActiveRouteSnapshot获取URL段的角度,javascript,angularjs,typescript,Javascript,Angularjs,Typescript,我需要从RouteIconsole.log获取URLSEMENT,并将输出附加到SS中 canActivateChild(childRoute: ActivatedRouteSnapshot) { console.log(childRoute) } 我想在\urlSegment中获取段数组,如何实现这一点有帮助吗 注意:所有以开头的键都是私有的。是否有其他方法可以获得所需的结果,即段数组 我找到了获取\u urlSegments的解决方案canActivateChild()方法中还有
Route
Iconsole.log
获取URLSEMENT,并将输出附加到SS中
canActivateChild(childRoute: ActivatedRouteSnapshot) {
console.log(childRoute)
}
我想在\urlSegment
中获取段
数组,如何实现这一点有帮助吗
注意:所有以开头的键都是私有的。是否有其他方法可以获得所需的结果,即段数组
我找到了获取\u urlSegments
的解决方案canActivateChild()
方法中还有另一个参数state
,它返回当前完整的URL,我们可以解析并获取段,示例如下:
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const tree = this.router.parseUrl(state.url);
const children = tree.root.children[PRIMARY_OUTLET];
const segments = children.segments;
console.log(segments[1].path); //which is 'orientation' - see above SS
}
供参考