Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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
Ionic framework 如何使用tabs.router.module中的route触发Ionic 4中的ionViewWillLeave_Ionic Framework_Ionic4_Angular Lifecycle Hooks - Fatal编程技术网

Ionic framework 如何使用tabs.router.module中的route触发Ionic 4中的ionViewWillLeave

Ionic framework 如何使用tabs.router.module中的route触发Ionic 4中的ionViewWillLeave,ionic-framework,ionic4,angular-lifecycle-hooks,Ionic Framework,Ionic4,Angular Lifecycle Hooks,将所有页面路由放置在TabsAgerOutingModule中时,不会触发生命周期挂钩ionViewWillLeave/ionViewDidLeave 我们将路由从app routing.module.ts更改为tabs.router.module.ts,以获得爱奥尼亚4应用程序中选项卡栏的完整视图。这些路线运行良好。 当路由位于app routing.module.ts中时,离开页面(并关闭当前的可观察对象)时,始终会触发ionViewWillLeave。现在,离开页面时不会触发ionView

将所有页面路由放置在TabsAgerOutingModule中时,不会触发生命周期挂钩
ionViewWillLeave
/
ionViewDidLeave

我们将路由从
app routing.module.ts
更改为
tabs.router.module.ts
,以获得爱奥尼亚4应用程序中选项卡栏的完整视图。这些路线运行良好。
当路由位于
app routing.module.ts
中时,离开页面(并关闭当前的
可观察对象
)时,始终会触发
ionViewWillLeave
。现在,离开页面时不会触发
ionViewWillLeave

在tabs.router.module.ts中路由

const routes: Routes = [
  {
    path: 'tabs',
    component: TabsPage,
    children: [
      {
        path: '',
        redirectTo: '/tabs/(home:home)',
        pathMatch: 'full',
      },
      {
        path: 'home',
        outlet: 'home',
        component: HomePage
      },
      {
        path: 'chats',
        outlet: 'chats',
        component: ChatsPage
      },
...
const routes: Routes = [
  { path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: 'chats', loadChildren: './chats.module#ChatsPageModule' },
...
在TS文件中记录ionViewWillLeave失败

ionViewWillEnter() {
  console.log('ionViewWillEnter');  // <- In console when entering
}
ionViewWillLeave() {
  console.log('ionViewWillLeave');  // <- Not in console when leaving
}
ionViewWillEnter() {
  console.log('ionViewWillEnter');  // <- In console when entering
}
ionViewWillLeave() {
  console.log('ionViewWillLeave');  // <- In console when leaving
}
IonView的日志记录成功将保留在TS文件中

ionViewWillEnter() {
  console.log('ionViewWillEnter');  // <- In console when entering
}
ionViewWillLeave() {
  console.log('ionViewWillLeave');  // <- Not in console when leaving
}
ionViewWillEnter() {
  console.log('ionViewWillEnter');  // <- In console when entering
}
ionViewWillLeave() {
  console.log('ionViewWillLeave');  // <- In console when leaving
}
ionViewWillEnter(){

console.log('ionViewWillEnter');//我们问题的解决方案

中断对选项卡的更改

停止在tab router中使用outlet/component,现在我们直接将子页面放置在选项卡路径中

{
  path: 'tabs',
  component: TabsPage,
  children: [
    {
      path: 'home',
      children: [
        {
          path: '',
          loadChildren: '../home/home.module#HomePageModule'
        },
        {
          path: 'chats'
          children: [
          {
            path: '',
            loadChildren: '../chats/chats.module#ChatsPageModule'
          }
        ]
      },
...

ionViewWillLeave/ionViewDidLeave被触发了吗?找到了解决方案吗?@Jonathan我的问题在我对特定构建应用突破性更改时得到了解决。你是否面临类似的问题?