我在NativeScript 3.4中遇到路由问题,这让我感到疯狂。这个测试project的想法是,根应用程序组件正在使用<page-router-outlet>
,然后使用<router-outlet>
使用嵌套的角度路由,它会加载一个登录父级和子级,我将通过它导航到一个主页面,有两个子路径。
如果我使用login.child.ts
从this.router.navigate(['/main']);
路由到主要父/子,那么一切正常,我继续在两个孩子之间交替。
但是,如果我使用清除历史this.router.navigate(['/main'],{ clearHistory: true });
路由到主要,这是我想要的,因为登录后我不希望用户能够“返回”登录,那么我就是正确地与第一个孩子一起到达主要父母,但后来无法导航到另一个孩子。
关于我做错了什么的想法?
这是我正在使用的路由:
const routes: Routes = [
{ path: "", redirectTo: "login", pathMatch: "full" },
{ path: "login", component: LoginParent,
children: [
{ path: "", redirectTo: "loginchild", pathMatch: "full" },
{ path: "loginchild", component: LoginChild },
]
},
{ path: "main", component: MainParent,
children: [
{ path: "", redirectTo: "mainchild", pathMatch: "full" },
{ path: "mainchild", component: MainChild },
{ path: "otherchild", component: OtherChild },
]
}
];
编辑:当我将主路径包装在包含<page-router-outlet>
的组件中时,如下所示,那么一切都开始工作了。但似乎有点麻烦。我很乐意理解它是如何更整洁的(也许NativeScript 4中的更改允许更容易处理)?
const routes: Routes = [
{ path: "", redirectTo: "login", pathMatch: "full" },
{ path: "login", component: LoginParent,
children: [
{ path: "", redirectTo: "loginchild", pathMatch: "full" },
{ path: "loginchild", component: LoginChild },
]
},
{ path: "main", component: AppComponent,
children: [
{ path: "", component: MainParent,
children: [
{ path: "", redirectTo: "mainchild", pathMatch: "full" },
{ path: "mainchild", component: MainChild },
{ path: "otherchild", component: OtherChild },
]
}
]
}
];