【发布时间】:2021-06-28 07:04:44
【问题描述】:
我在 app-routing.module 中有以下内容:
const routes: Routes = [
{
path: 'displayfile/:navitemid',
loadChildren: () => import('./pages/file-viewer/file-viewer.module').then( m => m.FileViewerPageModule),
canActivate: [DisplayFileGuardService]
},
{
path: 'file-viewer',
loadChildren: () => import('./pages/file-viewer/file-viewer.module').then( m => m.FileViewerPageModule)
},
{
path: 'settings',
loadChildren: () => import('./pages/settings/settings.module').then( m => m.SettingsPageModule)
},
{
path: '',
loadChildren: () => import('./pages/file-viewer/file-viewer.module').then( m => m.FileViewerPageModule),
}
];
像“http://localhost:8100/displayfile/1234”这样的 URL 应该匹配第一个路由。在我重构我的应用程序以引入选项卡式界面之前,它就是这样做的。但它似乎忽略了这条路线。
我的 file-viewer-routing.module 包含下面的选项卡。我已经阅读了文档并尝试了许多不同的组合但没有成功。我已经登录了“DisplayFileGuardService”构造函数和 canActivate 方法。所以我知道它没有被击中。如果我将该守卫添加到最后一条路线,那么它确实会被上面失败的 URL 击中。为什么它会掉到空路由并忽略我的显示文件路由?
const routes: Routes = [
{
path: 'tabs',
component: FileViewerPage,
children: [
{
path: 'tab1',
loadChildren: () => import('../tab1/tab1.module').then(m => m.Tab1PageModule),
//canActivate: [DisplayFileGuardService]
},
{
path: 'tab2',
loadChildren: () => import('../tab2/tab2.module').then(m => m.Tab2PageModule)
},
{
path: 'tab3',
loadChildren: () => import('../tab3/tab3.module').then(m => m.Tab3PageModule)
},
{
path: 'tab4',
loadChildren: () => import('../tab4/tab4.module').then(m => m.Tab4PageModule)
},
{
path: 'tab5',
loadChildren: () => import('../tab5/tab5.module').then(m => m.Tab5PageModule)
},
{
path: '',
redirectTo: '/tabs/tab1',
pathMatch: 'full'
}
]
},
{
path: '',
redirectTo: '/tabs/tab1',
pathMatch: 'full'
}
【问题讨论】:
标签: angular ionic-framework routes