首页 > 解决方案 > 登录后单击硬件后退按钮导航到登录页面如何在离子4中防止它

问题描述

const routes: Routes = [
  {
    path: '',
    component: TabsPage,
    children: [
      //new page add
      {
        path: 'home',
        children: [
          {
            path: '', loadChildren: () => import('../AllPages/home/home.module').then(m => m.HomePageModule)
          },
          {
            path: 'new-arrival',
            children: [
              {
                path: '',
                loadChildren: () => import('../AllPages/new-arrival/new-arrival.module').then(m => m.NewArrivalPageModule)
              },

              {
                path: 'product-item-list',
                children: [
                  {
                    path: '',
                    loadChildren: () => import('../Allpages/product-item-list/product-item-list.module').then(m => m.ProductItemListPageModule)
                  },

                  {
                    path: 'product-details',
                    children: [
                      {
                        path: '',
                        loadChildren: () => import('../Allpages/product-details/product-details.module').then(m => m.ProductDetailsPageModule)
                      },
                    ]

                  }
                ]
              }


            ]
          },

标签: javascriptangularionic4angular9

解决方案


使用 Ionic NavController 而不是 Angular Router。
然后,使用navigateRoot方法。

意味着堆栈中的所有现有页面都将被删除,导航页面将成为堆栈中的单个页面。

import { NavController } from '@ionic/angular';
...
constructor(private navController: NavController) {}
...
this.navController.navigateRoot('/tabs/home');

推荐阅读