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

相关内容

热门资讯

wepoke模拟器!wepok... wepoke模拟器!wepoke线上,wePoke都是真的有挂,解密教程(有挂教程);玩家必备必赢加...
总算了解!!德扑真的有挂一直,... 总算了解!!德扑真的有挂一直,德扑之星底牌一直有挂(详细ai代理教程)1、快速入门:当你通过点击开始...
wepokeai机器人!wep... wepokeai机器人!wepoke系统规律(透视)wepoke(果然真的有挂)是一款可以让一直输的...
透视辅助!微扑克有机器人吗,(... 透视辅助!微扑克有机器人吗,(微扑克机器人)总是有挂(详细全自动机器人教程),您好,这款游戏可以开挂...
wepokeai代打的胜率!w... wepokeai代打的胜率!wopoker有外 挂,wePoke好像真的有挂,安装教程(有挂细节);...
透视辅助!红龙扑克总是有挂,红... 透视辅助!红龙扑克总是有挂,红龙扑克确实真的是有挂(详细辅助工具教程)1、超多福利:超高返利,海量正...
wpk提高胜率!WPk就是真的... wpk提高胜率!WPk就是真的有挂,wpK都是真的有挂,系统教程(有挂教程);该软件可以轻松地帮助玩...
教你攻略!wopoker轻量版... wopoker新手教程相关信息汇总(需添加指定薇757446909获取下载链接);教你攻略!wopo...
wpk德州透视辅助!WpK一般... wpk德州透视辅助!WpK一般真的有挂,wPk都是真的有挂,德州论坛(有挂插件);1、完成wpk透视...
揭秘!德扑真的有挂竟然,德扑之... 一、简介了解软件请加微:136704302是一款在线扑克游戏平台,玩家可以在平台上进行多人在线扑克游...