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">
|
<script setup lang="ts">
|
||||||
import { RouterView } from 'vue-router'
|
import { RouterView } from 'vue-router'
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
import OverlayBadge from 'primevue/overlaybadge';
|
import OverlayBadge from 'primevue/overlaybadge';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const page_title = ref();
|
||||||
|
|
||||||
|
watch(() => route.meta, (newVal, oldVal) => {
|
||||||
|
page_title.value = newVal.title;
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -75,7 +84,7 @@ import OverlayBadge from 'primevue/overlaybadge';
|
||||||
>
|
>
|
||||||
<i class="pi pi-bars text-4xl" />
|
<i class="pi pi-bars text-4xl" />
|
||||||
</a>
|
</a>
|
||||||
<span class="title">Page Title</span>
|
<span class="title">{{ page_title }}</span>
|
||||||
</div>
|
</div>
|
||||||
<a
|
<a
|
||||||
v-styleclass="{
|
v-styleclass="{
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,28 @@ const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: '/',
|
|
||||||
name: 'home',
|
|
||||||
component: HomeView,
|
component: HomeView,
|
||||||
|
meta: {
|
||||||
|
title: 'Home',
|
||||||
|
},
|
||||||
|
name: 'home',
|
||||||
|
path: '/',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/about',
|
|
||||||
name: 'about',
|
|
||||||
component: AboutView,
|
component: AboutView,
|
||||||
|
meta: {
|
||||||
|
title: 'About',
|
||||||
|
},
|
||||||
|
name: 'about',
|
||||||
|
path: '/about',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/sticker',
|
|
||||||
name: 'sticker',
|
|
||||||
component: StickerView,
|
component: StickerView,
|
||||||
|
meta: {
|
||||||
|
title: 'Sticker',
|
||||||
|
},
|
||||||
|
name: 'sticker',
|
||||||
|
path: '/sticker',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue