add active state to route links

This commit is contained in:
axolotle
2021-03-10 18:37:06 +01:00
parent 43f558ad2f
commit 206e297576
+15 -20
View File
@@ -8,17 +8,8 @@
<span class="sr-only">Menu</span> <span class="sr-only">Menu</span>
</template> </template>
<b-dropdown-item :to="{ name: 'home' }"> <b-dropdown-item v-for="name in subRoutes" :key="name" :to="{ name }">
{{ $t('sections.home') }} {{ $t('sections.' + name) }}
</b-dropdown-item>
<b-dropdown-item :to="{ name: 'introduction' }">
{{ $t('sections.introduction') }}
</b-dropdown-item>
<b-dropdown-item :to="{ name: 'blog' }">
{{ $t('sections.blog') }}
</b-dropdown-item>
<b-dropdown-item :to="{ name: 'contact' }">
{{ $t('sections.contact') }}
</b-dropdown-item> </b-dropdown-item>
</b-dropdown> </b-dropdown>
@@ -26,15 +17,12 @@
{{ $t('title') }} {{ $t('title') }}
</b-navbar-brand> </b-navbar-brand>
<b-nav class="ml-auto"> <b-nav class="ml-auto" pills>
<b-nav-item :to="{ name: 'library' }"> <b-nav-item
{{ $t('sections.library') }} v-for="name in mainRoutes" :key="name"
</b-nav-item> :to="{ name }" :active="$route.name === name"
<b-nav-item :to="{ name: 'kit' }"> >
{{ $t('sections.kit') }} {{ $t('sections.' + name) }}
</b-nav-item>
<b-nav-item :to="{ name: 'gallery' }">
{{ $t('sections.gallery') }}
</b-nav-item> </b-nav-item>
</b-nav> </b-nav>
</b-navbar> </b-navbar>
@@ -59,6 +47,13 @@ export default {
// all titles will be injected into this template // all titles will be injected into this template
titleTemplate: '%s | ' + this.$t('title') titleTemplate: '%s | ' + this.$t('title')
} }
},
data () {
return {
mainRoutes: ['library', 'kit', 'gallery'],
subRoutes: ['home', 'introduction', 'blog', 'contact']
}
} }
} }
</script> </script>