Skip to content

Commit 8fe145a

Browse files
committed
make page title update on client-side navigation
1 parent 9e2ee4d commit 8fe145a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/App.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,27 @@
1414
</template>
1515

1616
<script setup>
17+
import { ref, watch } from "vue";
1718
import { showingNavigationMenu } from "./globals.js"
1819
import { Head } from "@unhead/vue/components";
1920
import { useRoute } from "vue-router";
2021
2122
import Navigation from "./components/Navigation";
2223
2324
const route = useRoute();
24-
const { title, description, image } = useRoute()?.meta;
25+
26+
// load route metadata for initial-server side render
27+
const title = ref(route?.meta?.title);
28+
const description = ref(route?.meta?.description);
29+
const image = ref(route?.meta?.image);
30+
31+
watch(route, (to) => {
32+
// update route metadata on client-side navigation
33+
title.value = to?.meta?.title;
34+
description.value = to?.meta?.description;
35+
image.value = to?.meta?.image;
36+
}, {flush: 'pre', immediate: true, deep: true});
37+
2538
</script>
2639
2740
<style lang="scss">

0 commit comments

Comments
 (0)