Add StyledLink

This commit is contained in:
ekzyis 2023-11-26 22:28:38 +01:00
parent 6d7cd2573d
commit 46c2a4eceb
3 changed files with 23 additions and 3 deletions

View File

@ -0,0 +1,16 @@
<template>
<router-link :to="to" :class="{ selected }">
<slot></slot>
</router-link>
</template>
<script setup>
import { computed, defineProps } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
const props = defineProps(['to'])
const selected = computed(() => props.to !== '/' ? route.path.startsWith(props.to) : route.path === props.to, [route.path])
</script>

View File

@ -24,7 +24,7 @@ const routes = [
path: '/user', path: '/user',
component: UserView, component: UserView,
children: [ children: [
{ path: '', name: 'user', component: UserHome }, { path: 'settings', name: 'user', component: UserHome },
{ path: 'invoices', name: 'invoices', component: UserInvoices } { path: 'invoices', name: 'invoices', component: UserInvoices }
] ]
}, },

View File

@ -11,8 +11,8 @@
<!-- eslint-enable --> <!-- eslint-enable -->
<header class="flex flex-row text-center justify-center pt-1"> <header class="flex flex-row text-center justify-center pt-1">
<nav> <nav>
<router-link to="/user">settings</router-link> <StyledLink to="/user/settings">settings</StyledLink>
<router-link to="/user/invoices">invoices</router-link> <StyledLink to="/user/invoices">invoices</StyledLink>
</nav> </nav>
</header> </header>
<Suspense> <Suspense>
@ -20,6 +20,10 @@
</Suspense> </Suspense>
</template> </template>
<script setup>
import StyledLink from '@/components/StyledLink'
</script>
<style scoped> <style scoped>
nav { nav {
display: flex; display: flex;