【发布时间】:2021-12-01 05:10:26
【问题描述】:
几天以来,我一直在尝试制作简单的 ionic tab 组件。我有一个屏幕,用户在底部插槽上有 3 个选项卡。单击选项卡时,会为选项卡触发 ngOnInit 函数,但我似乎无法加载与组件关联的 Html。有什么想法可能是错的吗?我在 ngOnInit 方法中放置了一条控制台日志消息,它在控制台中显示了该消息,因此我认为路由配置正确。我还可以看到 URL 发生了变化。
我的 HTML 代码:
<ion-tab-button tab="journey">
<ion-icon name="walk"></ion-icon>
<ion-label>Journey</ion-label>
</ion-tab-button>
<ion-tab-button tab="learning">
<ion-icon name="book"></ion-icon>
<ion-label>Current Learning</ion-label>
<ion-badge>6</ion-badge>
</ion-tab-button>
<ion-tab-button tab="profile">
<ion-icon name="information-circle"></ion-icon>
<ion-label>Profile</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</ion-toolbar>
我尝试过使用离子页面,然后也尝试使用离子组件。两种方法都显示 ngOnInit 触发和 URL 转换的相同行为,但与选项卡关联的 HTML 不会加载。
我的 routing-module.ts 代码
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ChildDetailPage } from './child-detail.page';
import { CurrentLearningPageModule } from '../../current-learning/current-learning.module';
import { CurrentLearningComponent } from '../../current-learning/current-learning.component';
import { ProfileComponent } from '../../profile/profile.component'
const routes: Routes = [
{
path: '',
component: ChildDetailPage,
children:[
{
path: 'journey',
children:
[
{
path: '',
loadChildren: './child-detail.page'
}
]
},
{
path: 'learning',
children:
[
{
path: '',
//loadChildren: '../../current-learning/current-learning.module#CurrentLearningPageModule'
// loadChildren: () => import('../../current-learning/current-learning.module').then( m => m.CurrentLearningPageModule)
component: CurrentLearningComponent
}
]
},
{
path: 'profile',
loadChildren: () => import('../../profile/profile.component').then( m => m.ProfileComponent)
},
// {
// path: '',
// redirectTo: 'journey',
// pathMatch: 'full'
// }
]
},
{
//path: '',
//redirectTo: 'child/child-detail/',
//pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class ChildDetailPageRoutingModule {}
任何帮助将不胜感激!
【问题讨论】:
-
您能否在单击选项卡后提供更改的路由 url。看来您的子路线应该像“childDetailsPage”一样不在子系统中。
-
这是我单击标签localhost:8100/child/child-detail/learning 后更改的 URL。标签页 html 没有改变,只有 ngOnInit 被触发。我还检查了其他离子生命周期方法正在触发
标签: ionic-framework angular8 angular-routing