简体   繁体   English

Nativescript + Angular,如何到达嵌套页面路由器出口中的子路由?

[英]Nativescript + Angular, How do I reach child routes in a nested page router outlet?

I would like to achieve tabview navigation in a NS + Angular 7 app.我想在 NS + Angular 7 应用程序中实现 tabview 导航。

Here is my current setup:这是我目前的设置:

app-routing.module.ts: app-routing.module.ts:

...

const routes: Routes = [
    { path: '', redirectTo: '/login', pathMatch: 'full' },
    { path: 'login', component: LoginComponent },
    { path: 'tabs', loadChildren: '~/app/tabs/tabs.module#TabsModule'; }
];

...

tabs.module.ts: tabs.module.ts:

...
NativeScriptRouterModule.forChild([
            {   path: 'def',
                component: TabsComponent,
                children: [
                  {
                      path: 'market',
                      outlet: 'market',
                      component: NSEmptyOutletComponent,
                      loadChildren: '~/app/market/market.module#MarketModule'
                  },
                  {
                      path: 'list',
                      outlet: 'list',
                      component: NSEmptyOutletComponent,
                      loadChildren: '~/app/list/list.module#ListModule'
                  },
                  {
                      path: 'search',
                      outlet: 'search',
                      component: NSEmptyOutletComponent,
                      loadChildren: '~/app/search/search.module#SearchModule'
                  },
                  {
                      path: 'insight',
                      outlet: 'insight',
                      component: NSEmptyOutletComponent,
                      loadChildren: '~/app/insights/insights.module#InsightsModule'
                  },
                  {
                      path: 'explore',
                      outlet: 'explore',
                      component: NSEmptyOutletComponent,
                      loadChildren: '~/app/explore/explore.module#ExploreModule'
                  }
            ]}
          ])
...

and finally one of the 5 routing modules, lets go with list-routing.module.ts:最后是 5 个路由模块之一,让我们使用 list-routing.module.ts:

...
const routes: Routes = [
    { path: '', redirectTo: 'list' },
    { path: 'list', component: ListComponent },
    { path: 'all', component: ListListComponent }
]
...

I think I'm getting mixed up because of the tabs coming in only after you pass the login screen.我想我很困惑,因为只有在您通过登录屏幕后才会出现标签。 After a successful login, I'm doing:成功登录后,我正在做:

this.router.navigate(['tabs/def'], {
                        transition: {
                          name: 'fade',
                          duration: 100,
                          curve: 'linear'
                        },
                        clearHistory: true
                    }

this does get me into the market outlet, displaying my 'home' screen.这确实让我进入了市场,显示了我的“主”屏幕。 And then if I do click on one of the tabs using:然后,如果我确实使用以下选项单击其中一个选项卡:

tabs.component.html: tabs.component.html:

<TabView class="fal" style="font-size: 20; padding: 3;" >
    <page-router-outlet *tabItem="{title: 'home'}" name="market"></page-router-outlet>
    <page-router-outlet *tabItem="{title: 'clipboard-list'}" name="list"></page-router-outlet>
    <page-router-outlet *tabItem="{title: 'search'}" name="search"></page-router-outlet>
    <page-router-outlet *tabItem="{title: 'lightbulb'}" name="explore"></page-router-outlet>
    <page-router-outlet *tabItem="{title: 'newspaper'}" name="insight"></page-router-outlet>
</TabView>

I am then taken to the correct outlet.然后我被带到正确的出口。 Here is where the problem is: List Component will load fine, but once I click on one of my lists, to get to ListListComponent, it tells me:这就是问题所在:List Component 可以正常加载,但是一旦我单击我的一个列表以访问 ListListComponent,它就会告诉我:

Error: Cannot match any routes. URL Segment: 'tabs/def'

The way I'm setting up this last navigation is:我设置最后一个导航的方式是:

this.router.navigate( [ { outlets: { list: [ '/all' ] } }], { relativeTo: this.route })

I've tried several combinations of passing in a URL of 'tabs/def/all' or 'tabs/def' with no success.我尝试了几种传入“tabs/def/all”或“tabs/def”的 URL 的组合,但都没有成功。 As I understand it, I pass a URL at the beginning, but now that I'm nested, I should just go across the outlet.据我了解,我在开始时传递了一个 URL,但现在我是嵌套的,我应该穿过出口。 So is my syntax just way off on this last router.navigate?那么我的语法在最后一个 router.navigate 上就差了吗?

Thank you so much for your help!!非常感谢你的帮助!!

Figured it out!弄清楚了! You don't need to specify outlet in the feature module routing.您不需要在功能模块路由中指定插座。 For anyone else who finds this:对于发现此内容的任何其他人:

Feature routing module:特征路由模块:

const routes: Routes = [
    {   path: '',
        component: ListComponent,
        children: [
            {
                path: '',
                children: [
                    {   path: '', redirectTo: 'all' },
                    {   path: 'all', component: ListListComponent },
                    {   path: 'group', component: ListgroupComponent },
                ]
            }
        ]
    }
];

list.component:列表组件:

<page-router-outlet></page-router-outlet>

navigation from ListListComp -> ListgroupComp (triggered by tap on element):从 ListListComp -> ListgroupComp 导航(通过点击元素触发):

this.router.navigate([ '../group' ], { relativeTo: this.route }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM