Vue

vue/link-for-navigation

Navigate with RouterLink or NuxtLink, not a button whose click handler only calls router.push or navigateTo.

umiarkowanastatyczneWCAG 4.1.2 · Afe-vue

Dlaczego

A button that calls router.push('/pricing') is announced as a button, not a link, cannot be opened in a new tab, copied or middle-clicked, has no address on hover, and is not prefetched. Screen reader users who list the links of a page do not find it.

Poprawka

Use <RouterLink to="/pricing"> (Vue Router) or <NuxtLink to="/pricing"> (Nuxt), and style it as a button if the design wants one. Keep router.push and navigateTo for navigation that follows an action, such as after a form is saved.

Przykłady

<!-- bad -->
<button type="button" @click="router.push('/pricing')">See pricing</button>
<!-- good -->
<RouterLink to="/pricing" class="button">See pricing</RouterLink>

Źródła

Fakty

Identyfikator
vue/link-for-navigation
Waga
umiarkowana
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
vue
Tylko w projektach z
vue nuxt
WCAG 2.2
4.1.2, poziom A
Uczy jej skill
fe-vue Vue components
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain vue/link-for-navigation