gpt4 book ai didi

angular - 带有固定侧边栏和 Angular 导航栏的路由器导出导航

转载 作者:行者123 更新时间:2023-12-04 17:34:57 25 4
gpt4 key购买 nike

我对如何放置路由器 socket 有些困惑。我曾尝试研究类似的案例,但无济于事。
这是场景
我有一个仪表板组件,它在登录成功后加载。仪表板包含在 html 上声明的侧边栏、页脚和导航组件。现在,当我单击用户链接向我显示用户列表时,它会加载用户组件,但侧边栏、页脚和导航消失了,我只剩下用户组件。我只想要一个情况,当我点击侧边栏中的链接时,它只是改变了内容而不删除侧边栏、页脚和导航......
PS:用户组件有自己的模块,然后我像往常一样将其导入到appModule中。

这是我到目前为止所拥有的。

应用程序组件.html

<router-outlet></router-outlet>

仪表板.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>

用户路由文件
const routes: Routes = [
{ path: 'user/list', component: UsersComponent },
{ path: 'user/new', component: UserComponent },
];

应用模块
export const AppRoutes2: Routes = [
{ path: '', component: LoginComponent},
{ path: 'content', component: ContentComponent },
{ path: 'dashboard', component: DashboardComponent },
];

imports: [
BrowserModule,
RouterModule.forRoot(AppRoutes2, {useHash: false}),
HttpClientModule,
UsersModule,
],

如果我点击用户列表链接,侧边栏、导航和页脚就会消失。我希望它保持不变,只是更改内容区域。

请问,我做错了什么或做错了什么??

最佳答案

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>

关于angular - 带有固定侧边栏和 Angular 导航栏的路由器导出导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57057112/

25 4 0