我正在尝试在路线上传递参数,但它以未定义形式到达。 在登录屏幕上,我通过NavController选项卡进行调用,但是在ActivatedRoute选项卡中,路由以未定义的方式到达。
export class TabsPage {
logado = false;
id=0;
constructor(public navCtrl: NavController, private route: ActivatedRoute)
{
}
ngOnInit() {
this.route.queryParams.subscribe(params => {
this.id = params["id"];
});
if(this.id == undefined || this.id == null || this.id == NaN || this.id < 1){
this.navCtrl.navigateForward('/login');
this.logado = false;
}else{
this.logado = true;
this.navCtrl.navigateForward('/home');
}
}
}
答案 0 :(得分:0)
将您的逻辑移动到queryParams订阅中,以便仅在设置ID后运行:
ngOnInit() {
this.route.queryParams.subscribe(params => {
this.id = params["id"];
if (this.id == undefined || this.id == null || this.id == NaN || this.id < 1) {
this.navCtrl.navigateForward('/login');
this.logado = false;
} else {
this.logado = true;
this.navCtrl.navigateForward('/home');
}
});
}