[英]Angular 8 Lazy Load Module - Can't Navigate
I'm having the hardest time.我最难过。 I've setup what I think is the proper structure but the app isn't allowing me to navigate and worse, it's presenting me with the same page.
我已经设置了我认为正确的结构,但该应用程序不允许我导航,更糟糕的是,它向我展示了相同的页面。 I'm trying to navigate to /login but nothings working.
我正在尝试导航到 /login 但没有任何效果。
App Routing应用路由
const routes: Routes = [
///// OPEN ROUTES /////
{ path: "login", component: LoginComponent },
///// AUTHENTICATED ROUTES /////
{ path: "home", component: HomeComponent },
///// FEATURE MODULES (LAZY LOADED) /////
{
path: "clients",
loadChildren: () =>
import("./clients/clients.module").then((m) => m.ClientsModule),
},
///// CATCH ALL ROUTES /////
{ path: "not-authorized", component: NotAuthorizedComponent },
{ path: "", redirectTo: "home", pathMatch: "full" },
{ path: "**", component: PageNotFoundComponent },
];
Clients Routing Module客户端路由模块
const routes: Routes = [
{
path: "",
component: ClientsComponent,
children: [
{
path: ":id",
component: ClientDetailsComponent,
},
{
path: ":id/edit",
component: ClientEditComponent,
},
{
path: "add",
component: ClientAddComponent,
},
{
path: "**",
redirectTo: "",
},
],
},
];
The nav page simply has a routerLink="/login" on the A link导航页面的 A 链接上只有一个 routerLink="/login"
EDIT编辑
Forgot to unload the ClientsModule from the main app module, so, it was loading twice.忘记从主应用程序模块中卸载 ClientsModule,所以它加载了两次。
Things to check:检查事项:
Do you have router-outlet in app.component.html app.component.html 中是否有路由器插座
The client routing module is incorrect.客户端路由模块不正确。 More specific routes go to the top, and less specific routes go towards the bottom:
更具体的路线 go 到顶部,不太具体的路线 go 朝向底部:
children: [ { path: "add", ... }, { path: ":id", ... }, { path: ":id/edit", ... } ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.