我对如何放置路由器电源插座感到困惑。我曾尝试研究类似的案例,但无济于事。 这是场景 我有一个仪表板组件,该组件将在登录成功后加载。仪表板包含在html上声明的侧边栏,页脚和导航组件。现在,当我单击用户链接以向我显示用户列表时,它会加载用户组件,但侧边栏,页脚和导航消失了,只剩下用户组件了。我只想要一种情况,当我单击侧边栏中的链接时,它只是更改内容而没有删除侧边栏,页脚和导航…… PS:用户组件具有自己的模块,然后像往常一样将其导入到appModule中。
这是我到目前为止所拥有的。
app.component.html
<router-outlet></router-outlet>
dashboard.component.html
<side-bar></side-bar>
<topnav-bar></topnav-bar>
<content></content>
<footer></footer>
sidebar.component.html
<li>
<a id="formsli" (click)="anchorClicked($event)"
><i class="fa fa-user"></i> User<span class="fa fa-chevron-down"></span
></a>
<ul class="nav child_menu">
<li><a [routerLink]="['/user/list']">User List</a></li>
<li><a [routerLink]="['/user/new']">New User</a></li>
</ul>
</li>
usersRouteFile
const routes: Routes = [
{ path: 'user/list', component: UsersComponent },
{ path: 'user/new', component: UserComponent },
];
appModule
export const AppRoutes2: Routes = [
{ path: '', component: LoginComponent},
{ path: 'content', component: ContentComponent },
{ path: 'dashboard', component: DashboardComponent },
];
imports: [
BrowserModule,
RouterModule.forRoot(AppRoutes2, {useHash: false}),
HttpClientModule,
UsersModule,
],
如果我单击用户列表链接,则侧边栏,导航和页脚会消失。我希望它保留下来,只是更改内容区域。
请问,我在做错什么还是做错了什么??
答案 0 :(得分:0)
App.component.html
//use the ngIf directive to either create or destroy the div with static content (this is determined from the app.component.ta
<div class=‘user-nav’ *ngif=“isLoggedIn”>
<side-bar></side-bar>
<top-navbar></top-navbar>
</div>
//anything that is routed will show up here
<router-outlet></router-outlet>
//if you want the footer to only be available after logging in add it here too
<footer></footer>