【问题标题】:Angular 7 nested module routingAngular 7 嵌套模块路由
【发布时间】:2019-08-04 04:52:05
【问题描述】:

我不明白具有多个嵌套模块的路由是如何工作的。 RouteTree 对我来说看起来不错且正确

它一直有效到“更多”页面。单击 ContactPage 后,url 会发生变化,但视图不会呈现。

这是我的路由器的样子:

app.routing.module

const routes: Routes = [
  { path: '', loadChildren: './pages/tabs/tabs.module#TabsPageModule' }
];

@NgModule({
  imports: [
      RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule {}

tabs.routing.module

const routes: Routes = [
    {
        path: 'tabs',
        component: TabsPage,
        children: [
            {
                path: 'more',
                loadChildren: '../more/more.module#MorePageModule'
            },
            {
                path: '',
                redirectTo: 'home',
                pathMatch: 'full'
            }
        ]
    },
    {
        path: '',
        redirectTo: 'tabs/home',
        pathMatch: 'full'
    }
];

@NgModule({
    imports: [
        RouterModule.forChild(routes)
    ],
    exports: [RouterModule]
})
export class TabsPageRoutingModule {
}

more.routing.module

const routes: Routes = [
    {
        path: '',
        component: MorePage,
        children: [
            {
                path: 'contact',
                component: ContactPage
            },
        ]
    }
];

@NgModule({
    imports: [
        RouterModule.forChild(routes)
    ],
    exports: [RouterModule]
})
export class MoreRouterModule {
}

contact.module

const routes: Routes = [
  {
    path: 'contact',
    component: ContactPage
  }
];

@NgModule({
  imports: [
    SharedModule,
    RouterModule.forChild(routes)
  ],
  declarations: [ContactPage],
  providers: [
  ]
})
export class ContactPageModule {}

我不知道问题是什么。有什么我遗漏的吗?

【问题讨论】:

    标签: angular ionic-framework routing ionic4


    【解决方案1】:

    请尝试重写以下内容(more.routing.module):

    const routes: Routes = [
        {
            path: '',
            component: MorePage,
            children: [
                {
                    path: 'contact',
                    component: ContactPage
                },
            ]
        }
    ];
    

    像这样使用loadChildren

    children: [
        {
            path: 'contact',
            loadChildren: 'path/to/contact.module#ContactPageModule'
        },
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-06
      • 2019-07-26
      • 2017-06-11
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      相关资源
      最近更新 更多