我正在尝试加载登录页面,但是它加载了两次
const routes: Routes = [
{ path: "", redirectTo: "login", pathMatch: "full" },
{ path: "login", component: LoginComponent },
{
path: "customer",
component: MainComponent,
children: [
{
path: "",
redirectTo: "create",
pathMatch: "full"
},
{
path: "create",
component: ContentComponent
},
{
path: "lookup",
component: LookupComponent
},
{
path: "report",
component: DatagridComponent
}
]
}
];
app.component.html
<app-login></app-login>
<router-outlet></router-outlet>
login.component.ts
login() {
this.router.navigate(['/customer']);
}
Aftr登录名,它将重定向到客户页。但是默认登录页面会加载两次。
答案 0 :(得分:1)
删除:
<app-login></app-login> -- remove this
<router-outlet></router-outlet>
您两次加载相同的组件。 您曾经用router-outlet来称呼它,一次在您发布应用程序登录标签时叫它
使用:
<router-outlet></router-outlet>
仅