ionic-framework - 离子标签不加载页面内容
问题描述
几天以来,我一直在尝试制作简单的 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 {}
任何帮助将不胜感激!
解决方案
派对迟到了,但对于任何在未来偶然发现这件事的人来说都很重要......
它不应该进入,ion-content
否则它将成为内容元素的一部分,并且您会遇到滚动等问题。
您应该将其添加到您的app.component.html
文件中:
<ion-app>
<ion-router-outlet></ion-router-outlet>
<ion-tabs>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="my-page-path">
<ion-icon name="calendar"></ion-icon>
<ion-label>My Page</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</ion-app>
推荐阅读
- tensorflow - 具有解析梯度/质量矩阵的快速哈密顿蒙特卡罗采样器
- c# - 如何将两个连接的套接字组合成一个对话?
- python - 如何在网页上制作pandas操作的进度条
- javascript - 有条件的问题,因为结果总是 else if
- python - 即使在使用类别权重进行训练后,二元分类神经网络也只能预测未见数据的一个值
- java - Apache POI - 加密大于 2GB 的 XLSX 文件失败
- delphi - 在 Fastreport 编辑器中获取选定的组件?
- python - Is tkinter code written the same for python 2 as it is in python 3?
- python - Python 替换使用正则表达式找到的所有匹配项
- excel - 刷新 CSV 导入时 Power Query 无法添加列