admin管理员组

文章数量:1312709

How can I add custom property (aria-selected) to link, if route is active? All docs talk about customizing class.

Something along those lines:

<!-- draw tabs -->
<ul>
  <li>
    <router-link
      :to="{ name: 'tab1' }"
      :aria-selected="isActive" <-- ???
    >
      Tab1
    </router-link>
    <router-link
      :to="{ name: 'tab2' }"
      :aria-selected="isActive" <-- ???
    >
      Tab2
    </router-link>
  ...

How can I add custom property (aria-selected) to link, if route is active? All docs talk about customizing class.

Something along those lines:

<!-- draw tabs -->
<ul>
  <li>
    <router-link
      :to="{ name: 'tab1' }"
      :aria-selected="isActive" <-- ???
    >
      Tab1
    </router-link>
    <router-link
      :to="{ name: 'tab2' }"
      :aria-selected="isActive" <-- ???
    >
      Tab2
    </router-link>
  ...
Share Improve this question edited Feb 1 at 13:57 JohnSmith asked Jan 31 at 16:00 JohnSmithJohnSmith 4721 gold badge5 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default -1

I need to check current route name:

<router-link
  :to="{ name: 'tab1' }"
  :aria-selected="$route.name === 'tab1'"
>
  Tab1
</router-link>

本文标签: vuejs3How to add custom property to Vue3 routerlink if route is activeStack Overflow