我正在尝试使用不同的参数导航到相同的组件。我可以通过激活路径订阅params,但无法从订阅中调用params内的router.navigate
sidemenu.component.ts
getTestValue(value:String){
this._router.navigate(['/example/home',value]);
} home.component.ts
ngOnInit() {
this.route.params.subscribe(params => {
let id = params['id']; // (+) converts string 'id' to a number
console.log("params value"+id)// I am able to get this value but it is
nout ipdating component
this._router.navigate(['/example/home',id]); // This is not getting called
}我知道我们可以选择使用this,但我不想使用this作为this启动另一个组件的ngOnInit钩子。
this._router.routeReuseStrategy.shouldReuseRoute = function() {
return false;
};https://localhost:4200/example/home/123
https://localhost:4200/example/home/456 //这不是组件未更新
发布于 2019-07-04 22:36:43
这很简单。只需使用对象将参数映射到key-value即可。
this._router.navigate(['/example/home', { id: id }])https://stackoverflow.com/questions/56889396
复制相似问题