我正在构建一个 Angular 7 应用程序。在这个应用程序中,我得到了嵌套路由。我希望能够检测到父路由使用的组件。我找到了一种在本地进行的方法,但这不适用于生产(输出不同)。
我使用这种方法:
checkIfChild() {
this.sub = this.route.parent.params.subscribe(params => {
if (params['id']) {
this.parentId = params['id'];
if (this.route.parent.component['name'] === 'ProjectShowComponent') {
this.parentType = 'Project';
} else if (this.route.parent.component['name'] === 'CompanyShowComponent') {
this.parentType = 'Company';
} else if (this.route.parent.component['name'] === 'ContactShowComponent') {
this.parentType = 'User';
}
}
});
}
this.route.parent.component['name'] 方法在本地输出名称,但在生产中仅输出字母 T。
我收到了这条消息
TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context.
检测哪个父路由激活了子路由以便我可以采取行动的正确方法是什么?