我开始从主页面导航到事务页面,然后从事务页面导航到详细信息页,现在从details页面导航到details页面,然后我传递带有状态的数据,这样当我向后导航时,我可以从事务页面访问它。
现在的问题是,当我从主页面进入事务页面时,这将导致一个错误,即core.js:6162 ERROR TypeError: Cannot read properties of null (reading 'extras')
,因为我只有在从details页面返回时才会传递状态。
当我仅从details页面导航时,如何仅从事务页面访问console.log(this.route.getCurrentNavigation().extras.state.example);
。如果我来自主页并导航到事务页面,则不应显示错误core.js:6162 error TypeError:。谢谢你的任何想法。
#用于访问事务页上数据的代码
console.log(this.route.getCurrentNavigation().extras.state.example);
#码
private _generateLocationFormForApproval() {
this._dealService.generateLocationSubmission(this.dealId)
.subscribe({
next: (res) => {
if (res.isSuccess) {
this.absoluteUri = res.absoluteUri;
}
},
error: err => this._notificationService.showError(err),
complete: noop,
});
}
goBack() {
this._route.navigateByUrl(`${this.headerOptions.breadCrumbs.backLink.link}?tab=2` , { state: { example: this.absoluteUri } });
}
发布于 2021-12-08 00:15:32
在构造函数中调用getCurrentNavigation
吗?
constructor(private router: Router) {
console.log(this.route.getCurrentNavigation().extras.state.example);
}
如果没有,那就试试。
https://stackoverflow.com/questions/70268397
复制相似问题