Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 离子导航器_Javascript_Angular_Ionic Framework - Fatal编程技术网

Javascript 离子导航器

Javascript 离子导航器,javascript,angular,ionic-framework,Javascript,Angular,Ionic Framework,对于我的应用程序的某些页面,我有navigateRoot,它根据条件重定向用户,但问题是当用户重定向到目标页面时,他们将失去使用“后退”按钮的能力 例子 如果我在视图中使用路由链接/按钮,我可以使用routerDirection=“forward”为用户激活后退按钮,但在这种情况下,我不确定如何使用路由方向 代码 const addToko=this.addToko.value; 这个。商店服务。商店( addToko.name, ).订阅( 数据=>{ this.alertService.pr

对于我的应用程序的某些页面,我有
navigateRoot
,它根据条件重定向用户,但问题是当用户重定向到目标页面时,他们将失去使用“后退”按钮的能力

例子 如果我在视图中使用路由链接/按钮,我可以使用
routerDirection=“forward”
为用户激活后退按钮,但在这种情况下,我不确定如何使用路由方向

代码
const addToko=this.addToko.value;
这个。商店服务。商店(
addToko.name,
).订阅(
数据=>{
this.alertService.presentToast(数据['message']);
this.navCtrl.navigateRoot('/toko'){
this.alertService.presentToast(错误['message']);
}
);
现在,由于此重定向是基于条件的,我更喜欢使用“后退”按钮的静态路由,示例逻辑如下:

1-如果用户没有商店,重定向到介绍页面

2-(此处介绍没有后退按钮-基于上面的示例代码)

3-如果用户在介绍页面中使用了后退按钮,请转到个人资料页面

有什么想法吗?

进入根目录意味着堆栈中的所有现有页面都将被删除

所以…如果你不想,你可以从“@angular/router”和setDirection使用常规路由器,如图所示

首先你需要从'@angular/Router'导入{Router}

constructor (private router: Router) {}
然后使用它,就像这样:

const addToko = this.addToko.value;
this.storeService.store(
  addToko.name,
).subscribe(
  data => {
    this.alertService.presentToast(data['message']);
    this.navCtrl.setDirection('root');
    this.router.navigate('/toko'); // this should be the same without delete all ... i hope it helped,
  },
  error => {
    this.alertService.presentToast(error['message']);
  }
);

如果您使用爱奥尼亚版本4,请遵循此方法

正常页面重定向
  • 你的页面是父页面。你要重定向到子页面吗

    this.router.navigate(['\child'])

  • 如果使用重定向传递数据,请使用此方法 parent.ts

    让navigationExtras:navigationExtras={ 声明:{ 用户:this.user } }; this.router.navigate(['child'],navigationExtras); }

  • child.ts

  • 资料:有

    构造函数(专用路由:ActivatedRoute,专用路由器:router){ this.route.queryParams.subscribe(参数=>{ if(this.router.getCurrentNavigation().extras.state){ this.data=this.router.getCurrentNavigation().extras.state.user; } }); }


  • “this.navCtrl”是@angular/Router中的路由器类型吗?如果您使用的是Ionic4/5,那么您应该使用
    Router.navigate()
    @Y_Moshe yes
    从'@ionic/angular'导入{NavController,MenuController}@alex87您能提供示例吗?您确定NavController中存在navigateRoot功能吗?因为我正在尝试搜索它,但没有看到该方法……这意味着我必须更改
    this.navCtrl.navigateRoot('/toko')
    或添加另一个类似
    this.navCtrl.setDirection('/profile')返回按钮工作?实际上,你可能不确定,需要省略“this.navCtrl.setDirection('root');”,因为你不想删除上一个。。。所以基本上只需要使用角度路由器。试试看:)我知道我的代码不是格式化的,你只要复制粘贴就可以了
    
    const addToko = this.addToko.value;
    this.storeService.store(
      addToko.name,
    ).subscribe(
      data => {
        this.alertService.presentToast(data['message']);
        this.navCtrl.setDirection('root');
        this.router.navigate('/toko'); // this should be the same without delete all ... i hope it helped,
      },
      error => {
        this.alertService.presentToast(error['message']);
      }
    );