AngularMaterial中的mat-list-item与routerLinkActive无法正常工作
创始人
2024-10-28 11:35:39
0
  1. 确保在mat-list中使用mat-list-item组件,并在每个mat-list-item上使用routerLink属性指定导航链接。
  2. 在根模块中导入RouterModule并在imports数组中使用RouterModule.forRoot(routes)配置路由。
  3. 在组件模块中导入RouterModule并在imports数组中使用RouterModule.forChild(routes)配置子路由。
  4. 在模板中的mat-list-item中指定routerLinkActive属性和routerLinkActiveOptions对象,以使选中状态得到正确的应用。

以下是示例代码:

app.module.ts:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  // 定义路由
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes)
  ],
  exports: [
    RouterModule
  ]
})
export class AppRoutingModule { }

component.module.ts:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { MyComponent } from './my.component';

const routes: Routes = [
  // 定义子路由
];

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(routes)
  ],
  declarations: [
    MyComponent
  ]
})
export class MyComponentModule { }

component.html:


  Home
  About

相关内容

热门资讯

我来教大家!福建天天开心辅助器... 我来教大家!福建天天开心辅助器是真的吗,天酷辅助器,详细app(有挂方针)1、超多福利:超高返利,海...
分享一款!点我休闲辅助器,大唐... 分享一款!点我休闲辅助器,大唐麻将开挂软件,详细工具(有挂攻略)1、超多福利:超高返利,海量正版游戏...
一分钟教你!微信小程序指尖四川... 一分钟教你!微信小程序指尖四川辅助器,多乐找刺激脚本,详细方法(有挂详细)1、超多福利:超高返利,海...
免费测试版!四川游戏家园通用辅... 免费测试版!四川游戏家园通用辅助,上品斗地主游戏辅助,详细app(有挂总结)该软件可以轻松地帮助玩家...
实测揭晓!798大菠萝辅助,边... 实测揭晓!798大菠萝辅助,边锋干瞪眼ios辅助,详细软件(有挂方略)边锋干瞪眼ios辅助能透视中分...
9分钟了解!多乐够级辅助软件,... 9分钟了解!多乐够级辅助软件,赣牌圈有挂吗,详细方法(有挂技巧)1、起透看视 多乐够级辅助软件辅助软...
技术分享!微信小程序辅助有哪些... 技术分享!微信小程序辅助有哪些,巴蜀长牌辅助,详细方法(有挂技术)1、微信小程序辅助有哪些公共底牌简...
一分钟快速了解!微信小程序游戏... 一分钟快速了解!微信小程序游戏破解微乐游戏,微乐小程序有脚本吗,详细工具(有挂工具)微信小程序游戏破...
玩家必看教程!小程序能不能开挂... 玩家必看教程!小程序能不能开挂,途游破解版无限钻石,详细神器(有挂教学)1、进入到途游破解版无限钻石...
六分钟了解!福建十三兵修改器,... 六分钟了解!福建十三兵修改器,随意玩免费辅助器有挂吗,详细app(有挂神器)1、进入游戏-大厅左侧-...