【问题标题】:NativeScript Angular - Unable to navigate between sibling views located in different page-router-outletsNativeScript Angular - 无法在位于不同页面路由器插座的同级视图之间导航
【发布时间】: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。我可以确认在导航后更改TabViewselectedIndex。只需使用带有主题的服务并在导航时触发它,然后您就可以订阅 TabView 所在的任何组件中可观察的主题并相应地更改索引。

标签: angular nativescript angular-routing nativescript-angular


【解决方案1】:

请在下面试试

this.router.navigate(["/map"], { 过渡: { 名称:'slideLeft', 持续时间:300 } });

尝试在组件中添加私有 activeRoute: ActivatedRoute

this.router.navigate([{ outlets: { search: ["map"] } }], { relativeTo: this.activeRoute });

【讨论】:

猜你喜欢
  • 2018-03-08
  • 1970-01-01
  • 2018-09-23
  • 1970-01-01
  • 2016-11-16
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
  • 2019-06-04
相关资源
最近更新 更多