【发布时间】:2021-02-01 11:15:58
【问题描述】:
当我点击带有 [routerLink] 的按钮时,URL 正在改变,但是!页面保留在相同的组件中 - 登录组件。 我能做些什么来解决它?
APP ROUTING MODULE:
const routes: Routes = [
{ path: "", redirectTo: "/login", pathMatch: "full" },
{
path: "login", component: LoginComponent, children:
[{ path: "admin", component: AdminComponent },
{ path: "company", component: CompanyComponent },
{ path: "customer", component: CustomerComponent }]
}
];
LOGIN COMPONENT HTML:
<div class="row center">
<div class="col-4">
<button style="height: 250px; width:100% ;"
[routerLink]="['admin']">Admin</button>
</div>
<div class="col-4">
<button style="height: 250px; width:100% ;"
[routerLink]="['company']">Company</button>
</div>
<div class="col-4">
<button style="height: 250px; width:100% ;"
[routerLink]="['customer']">Customer</button>
</div>
</div>
APP.COMPONENT.HTML:
<div class="container">
<div class="row">
<div class="col-12">
<router-outlet></router-outlet>
</div>
</div>
</div>
请帮忙!
【问题讨论】:
-
您还需要在子数组路由中指定空白路径 - { path: '', redirectTo: 'overview', pathMatch: 'full' } 像这样......在你的情况下何时重定向当空白编辑它。试试这个...希望它有帮助。
-
我加了没用...
标签: javascript html angular routes