Watch route and set page title.
This commit is contained in:
parent
8e7c20fde9
commit
0e28438740
2 changed files with 25 additions and 7 deletions
11
src/App.vue
11
src/App.vue
|
|
@ -1,6 +1,15 @@
|
|||
<script setup lang="ts">
|
||||
import { RouterView } from 'vue-router'
|
||||
import { ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import OverlayBadge from 'primevue/overlaybadge';
|
||||
|
||||
const route = useRoute();
|
||||
const page_title = ref();
|
||||
|
||||
watch(() => route.meta, (newVal, oldVal) => {
|
||||
page_title.value = newVal.title;
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -75,7 +84,7 @@ import OverlayBadge from 'primevue/overlaybadge';
|
|||
>
|
||||
<i class="pi pi-bars text-4xl" />
|
||||
</a>
|
||||
<span class="title">Page Title</span>
|
||||
<span class="title">{{ page_title }}</span>
|
||||
</div>
|
||||
<a
|
||||
v-styleclass="{
|
||||
|
|
|
|||
|
|
@ -7,19 +7,28 @@ const router = createRouter({
|
|||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: HomeView,
|
||||
meta: {
|
||||
title: 'Home',
|
||||
},
|
||||
name: 'home',
|
||||
path: '/',
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
name: 'about',
|
||||
component: AboutView,
|
||||
meta: {
|
||||
title: 'About',
|
||||
},
|
||||
name: 'about',
|
||||
path: '/about',
|
||||
},
|
||||
{
|
||||
path: '/sticker',
|
||||
name: 'sticker',
|
||||
component: StickerView,
|
||||
meta: {
|
||||
title: 'Sticker',
|
||||
},
|
||||
name: 'sticker',
|
||||
path: '/sticker',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue