【发布时间】:2019-11-29 05:22:53
【问题描述】:
我在我的 Nativescript Angular 项目中为选项卡使用 <page-router-outlet></page-router-outlet> 和 <BottomNavigation></BottomNavigation> 设置,并且在从 1 个子选项卡路由导航到另一个子选项卡路由时遇到问题。
所以这里是app-routing.module.ts:
const routes: Routes = [
{ path: '', redirectTo: '/auth', pathMatch: 'full' },
{ path: 'auth', component: AuthComponent },
{ path: 'individual-tasks', component: SpecificTasksComponent },
{
path: 'tabs',
component: TabsComponent,
children: [
{
path: 'feed',
loadChildren: '~/app/pages/feed/feed.module#FeedModule',
component: NSEmptyOutletComponent,
outlet: 'feedTab'
},
{
path: 'notification',
loadChildren: '~/app/pages/notification/notification.module#NotificationModule',
component: NSEmptyOutletComponent,
outlet: 'notificationTab'
},
{
path: 'create',
loadChildren: '~/app/pages/create/create.module#CreateModule',
component: NSEmptyOutletComponent,
outlet: 'createTab'
},
{
path: 'profile',
loadChildren: '~/app/pages/profile/profile.module#ProfileModule',
component: NSEmptyOutletComponent,
outlet: 'profileTab'
}
]
}
];
我目前正在尝试从创建选项卡模块导航到提要选项卡模块。这里是create-routing.module.ts:
const routes: Routes = [
{ path: '', redirectTo: 'create', pathMatch: 'full' },
{ path: 'create', component: CreateComponent },
{ path: 'create-tasks', component: CreateTasksComponent },
{ path: 'create-preview', component: CreatePreviewComponent }
];
那么,如果我目前在 create-preview 路线内,我该如何导航回 app-routing.module.ts 中的“标签/提要”出口?
我一直在尝试这个:
this.router.navigate([
'../tabs', {
outlets: { feedTab: ['feed'] }, relativeTo: this.activatedRoute
}
]);
但即使我明确写到导航应该是到 feedTab,它仍然导航到起始出口(配置文件)而不是 feed 出口。这就像所说的出口完全被忽略了......有什么想法吗???
【问题讨论】:
-
我不认为路由器让你能够切换标签。您必须更新标签的 selectedIndex,然后导航到您喜欢的特定标签。
-
我认为@Manoj 是正确的......现在我必须弄清楚如何从其子组件之一中更新 selectedIndex
-
使用带有行为主题的服务。从父组件监听主题,更新子组件的值。
标签: angular nativescript angular-routing angular2-nativescript nativescript-angular