代码之家  ›  专栏  ›  技术社区  ›  Chrillewoodz

NativeScript Angular-无法在位于不同页面路由器出口的同级视图之间导航

  •  1
  • Chrillewoodz  · 技术社区  · 7 年前

    我有这个 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

    但它们都会产生相同的结果。

    我可能做错了什么?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Vivek Rajyaguru    7 年前

    请在下面试试

    这路由器。导航([“/map”]{ 过渡:{ 名称:'slidelft', 持续时间:300 } });

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

    这路由器。导航([{outlets:{search:[“map”]}}],{relativeTo:this.activeRoute});