【问题标题】:Angular 8, how can I use the primary outlet route when i'm in another router outletAngular 8,当我在另一个路由器插座中时如何使用主插座路由
【发布时间】:2020-03-05 02:30:14
【问题描述】:

抱歉,我是 Angular 新手,不太了解路由器插座的工作原理。

    {path: 'organisation/:orga_id/event/:event_id', component: EventAdminComponent, children: [
            {path: 'general', component: GeneralComponent, outlet: 'tab'},
            {path: 'tickets', component: TicketsComponent, outlet: 'tab'},
            {path: 'commandes', component: TestSecondComponent, outlet: 'tab'},
            {path: 'stat', component: TestSecondComponent, outlet: 'tab'}
        ]},
    {path: 'organisation/:orga_id/event/:event_id/status-people/:ticket_id', component: StatusPeopleComponent},

所以,这是我的 app-routing.ts,我在页面中使用了选项卡路由器插座,我的路由当前是:

http://localhost:4200/admin/organisation/KHY1ODY0ZDUx/event/GKniQWmuVDM2/(tab:tickets)

如您所见,我发现自己位于名为选项卡的路由器插座中,我想要的是:从我返回到主插座的位置并转到此 url:

http://localhost:4200/admin/organisation/KHY1ODY0ZDUx/event/GKniQWmuVDM2/status-people/:ticket-id

我用 routerLink 尝试了很多东西,但没有任何效果,谁能解释我应该怎么做?

【问题讨论】:

    标签: angular router outlet


    【解决方案1】:

    而不是尝试直接导航到 URL:

    [routerLink]="['/foo/bar']"
    

    您必须手动设置网点,例如:

    [routerLink]="[{ outlets: { primary: '/foo/bar', tab: null } }]"
    

    这将在primary 出口中打开'/foo/bar' 并清除tab 出口。

    【讨论】:

    • 感谢您的回复,我尝试了您的解决方案,得到的是这样的网址:localhost:4200/admin/organisation/KHY1ODY0ZDUx/event/…
    • 你的 routerLink-value 是什么样的?
    • [routerLink]= "[{ outlets: { primary: '/admin/organisation/' + manageEvent.orgaId + '/event/' + manageEvent.eventId + '/status-people/' + item.id, tab: null } }]">。而这个值的结果就是上面的url。
    猜你喜欢
    • 2016-12-30
    • 2020-01-13
    • 1970-01-01
    • 2017-02-15
    • 2018-07-28
    • 1970-01-01
    • 2017-04-29
    • 2019-01-05
    • 2018-09-02
    相关资源
    最近更新 更多