我在NativeScript 3.4中有一个路由问题让我疯狂 . 这个测试的想法project是根应用程序组件正在使用 <page-router-outlet>
然后使用嵌套的角度路由使用 <router-outlet>
它加载登录父和子,我通过它导航到具有两个子路由的主页 .
如果我用 this.router.navigate(['/main']);
从 login.child.ts
路由到主父/子,那么一切正常,我继续在两个孩子之间交替 .
但是,如果我通过清除历史 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 },
]
}
];
Edit :当我将主路径包装在一个包含 <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 },
]
}
]
}
];