Active Link Selected Nebular for Angular
Asked Answered
I

1

8

i'm using nebular in my angular front application , and want to set the active link selected . how can i achieve it ?

I've tried with the selected property of the menuItem but it's applied only on the item object and there is no [routerLinkActive] option

@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"
              },
            ]
          },

        ];
Incorporated answered 5/6, 2019 at 16:12 Comment(2)
Have you tried routerLinkActive ?Shrieve
@Incorporated did you find any solutionBrow
R
1

Try adding pathMatch:'full' to the menu items

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'
    },
  ];
Rosol answered 7/6, 2020 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.