簡體   English   中英

Angular Routing - 沒有路徑的redirectTo子路由

[英]Angular Routing - redirectTo child route without path

我嘗試將子路由設置為在我輸入站點地址時加載的默認路由。

const routes: Routes = [
    {path: '', pathMatch: 'full', redirectTo: ''},
    {
        path: '', component: FrameDefaultComponent,
        children: [
            {path: '', component: SiteCalculatorComponent}
        ]
    },
];

但這不起作用......當我給SiteCalculatorComponent任何路由,如 calc 並從級別 1 重定向到'calc'然后它就可以工作了。 我知道......但關鍵是我想在“沒有”任何路徑的情況下加載它;)

這可能嗎? 如果是如何?

我有一個這樣的路由器:

 const firstRoutes: Routes = [ { path: '', children: [ { path: 'parent-url', children: secondRoutes } ] } ];

第二個是這樣的:

 export const secondRoutes: Routes = [ { path: '', children: [ { path: '', redirectTo: 'child-route', pathMatch: 'full' }, { path: 'child-route', component: ChildComponent } ] } ];

我的 ChildComponent 可以用 /child-route 或 /parent-url/child-route 調用。 我想禁用使用兩個路由調用我的函數,因此設置只能使用 /parent-url/child-route 調用它。

我不知道如何檢查是否有 /parent-url ,如果沒有,則在沒有 /parent-url 的情況下禁用調用 ChildComponent 。 在整個網址?

解決方案:

{
    path: '', component: FrameDefaultComponent,
    children: [
        {path: '', component: SiteCalculatorComponent}
    ]
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM