8

我在我的 Angular 前端应用程序中使用 nebular,并且想要设置选中的活动链接。我怎样才能实现它?

我已经尝试使用 menuItem 的 selected 属性,但它仅应用于项目对象并且没有 [routerLinkActive] 选项

@Component({
  selector: 'nebular-pages',
  styleUrls: ['nebular.component.scss'],
  template: `
    <ngx-sample-layout>
      <nb-menu [items]="menu"></nb-menu>
      <router-outlet></router-outlet>
    </ngx-sample-layout>
  `,
})
export class NebularComponent {
  menu: NbMenuItem[];
  constructor() { }
        this.menu = [
          {
            title: 'Page1',
            link: `/user/params`,
            icon: 'nb-grid-b-outline',
            home: true,
          },
          {
            title: 'Page2',
            link: '/user/options',
            icon: 'nb-arrow-thin-right',
          },

          {
            title: 'Page3',
            icon: 'nb-list',
            children:[
              {
                title: 'Costs',
                link: '/user/costs',
                icon: 'nb-arrow-thin-right',
              },
              {
                title: "Benifits",
                link: "/user/benifits",
                icon: "nb-compose"
              },
            ]
          },

        ];
4

1 回答 1

1

尝试将 pathMatch:'full' 添加到菜单项

items: NbMenuItem[] = [
    {
      title: 'Login',
      icon: 'person-outline',
      link: '/login',
      pathMatch:'full'
    },
    {
      title: 'Register',
      icon: 'lock-outline',
      link: '/register',
      pathMatch:'full'
    },
    {
      title: 'Logout',
      icon: 'unlock-outline',
      link: '/logout',
      pathMatch:'full'
    },
  ];
于 2020-06-07T15:57:29.433 回答