Angular 路由器.x27;行不通
我已尝试在成功删除数据后重定向页面。所以我把redirect router.navigate放在数据部分的subscribe中。但它不起作用,而且我也试过使用ngZone,但什么也没发生。我还想展示成功的信息。我怎样才能证明这一点 没有ngZone:Angular 路由器.x27;行不通,angular,angular2-routing,Angular,Angular2 Routing,我已尝试在成功删除数据后重定向页面。所以我把redirect router.navigate放在数据部分的subscribe中。但它不起作用,而且我也试过使用ngZone,但什么也没发生。我还想展示成功的信息。我怎样才能证明这一点 没有ngZone: const rid = params['rid']; this.roleSer.deleteRole(rid).subscribe( data => { this.router.navigate(
const rid = params['rid'];
this.roleSer.deleteRole(rid).subscribe(
data => { this.router.navigate(['viewroles']) },
error => { error }
);
});
使用ngZone:
const vrid = this.route.params.subscribe((params: Params) => {
const rid = params['rid'];
this.roleSer.deleteRole(rid).subscribe(
data => { this.zone.run(()=>{
this.router.navigate(['viewroles'])
}); },
error => { error }
);
});
创建一个重定向函数并使用它
const vrid = this.route.params.subscribe((params: Params) => {
const rid = params['rid'];
this.roleSer.deleteRole(rid).subscribe(
data => {
this.redirect('viewroles');
},
error => { error }
);
});
redirect(path): void {
this.router.navigate(['/' + path])
}
这是什么。zone.run(()?谢谢你的建议。我已经尝试过了。但是没有工作。你有什么错误?确保你的路径是正确的?