【发布时间】:2020-02-23 05:03:29
【问题描述】:
我是 Angular 的新手。我有这种情况:我的 HomeComponent 在 .html 页面中有一个对 Appmenucomponent 的“引用”。所以,我需要点击不同的菜单(每个都是一个新组件)并在同一个地方(div)打开,比如 HomeComponent。
home.component.html
<div class="wrapper">
<app-appmenu></app-appmenu>
<div class="content-wrapper">
<section class="content-header">
<section class="content">
<h1>Welcome, {{currentUser.firstName}}!</h1>
<router-outlet></router-outlet>
</section>
</section>
</div>
</div>
在 Appmenucomponent 的 .html 中,我有一个路由到 Menu1Component 的链接,但我不知道如何在 HomeComponent 的同一个“div”上打开它:
menu1.component.html
<li ><a [routerLink]="['/menu1']"><i class="fa fa-circle-o" ></i> Menu 1</a></li>
这是我所期望的图像:
app-routing.module.ts
const appRoutes: Routes = [
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'login', component: ApploginComponent },
{ path: 'menu1', component: Menu1Component},
// otherwise redirect to home
{ path: '**', redirectTo: '' }
];
home-routing.module.ts
const routes: Routes = [
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
];
app.component.html
<router-outlet></router-outlet>
menu1.component.html
<p>menu1 works!</p>
然后,我也有一个登录组件,它重定向到包含菜单的 HomeComponent。
【问题讨论】:
-
把
放在 homeComponent.html 的 section 标签中。这将适当地将路由器链接加载到路由器插座。 -
我把
和当我点击菜单 1 时打开但不在 homecomponent 的同一个地方。我松开了菜单和另一个左侧 div。 -
是的。这是
的主要组件。这就是您将所有内容放在一起的 app.componet。 -
分享你的路由!
-
我已经更新了路由
标签: angular