【发布时间】:2019-01-28 12:12:20
【问题描述】:
我有这个TabView 组件:
<TabView androidTabsPosition="bottom">
<page-router-outlet *tabItem="{title: 'Item 1'}" name="map"></page-router-outlet>
<page-router-outlet *tabItem="{title: 'Item 2'}" name="subscribe"></page-router-outlet>
</TabView>
路由器配置:
{
path: '',
redirectTo: '/(map:map//subscribe:subscribe)',
pathMatch: 'full'
},
{
path: 'map',
loadChildren: '~/app/routes/+map/map.module#MapModule',
outlet: 'map'
},
{
path: 'subscribe',
loadChildren: '~/app/routes/+subscribe/subscribe.module#SubscribeModule',
outlet: 'subscribe'
}
在 SubscribeModule 功能模块中,我有一个函数应该导航到 map 路由:
// The NativeScript router service
constructor(private router: RouterExtensions) {}
navigate(args) {
const item = this.items[args.index];
this.router.navigate(['map'], {
transition: {
name: 'slideLeft',
duration: 300
}
});
}
但我得到的只是Error: Cannot match any routes. URL Segment: 'map'。
我也尝试了以下方法:
- 使用
this.router.navigate([{outlets: {map: 'map'}}]导航到指定的出口 - 使用
this.router.navigate(['../', 'map'])导航 - 使用
navigateByUrl导航
但它们都产生相同的结果。
我做错了什么?
【问题讨论】:
-
我认为当您有多个网点时,您必须满足包含所有网点段的 URL。请参阅template-tab-navigation-ng 以获得干净的示例。
-
嗨,你能以任何方式解决这个问题吗?我遇到了完全相同的问题。
-
@DanielN。不..:/我认为一种解决方案可能是首先更改 TabView 的 selectedIndex,然后尝试导航..但这也可能会中断..
-
谢谢,我会在接下来的几天里试试这个,让你知道它是否有效。我很可能会在服务中使用 Subject 并将其绑定到 selectedIndex 属性,以便可以从任何组件更改它。
-
@DanielN。我可以确认在导航后更改
TabView的selectedIndex。只需使用带有主题的服务并在导航时触发它,然后您就可以订阅TabView所在的任何组件中可观察的主题并相应地更改索引。
标签: angular nativescript angular-routing nativescript-angular