feat: update the page title using a watcher

Added a watcher (watchEffect) to App.vue to update the page title
always when a dependency changes. The afterEach hook was removed from
the router.
This commit is contained in:
2026-07-28 17:24:33 +02:00
parent d5f80eba67
commit 255bbc0b7e
2 changed files with 12 additions and 7 deletions
+7 -1
View File
@@ -18,13 +18,19 @@ limitations under the License.
import Navbar from './features/nav/components/Navbar.vue';
import Footer from './features/footer/components/Footer.vue';
import { updatePageTitle } from './router';
import { useColorScheme } from './features/colorScheme/composables/useColorScheme';
import { ref, provide, watch } from 'vue';
import { ref, provide, watch, watchEffect } from 'vue';
import { useRoute } from 'vue-router';
const route = useRoute();
const { getColorScheme, updateColorScheme } = useColorScheme();
const colorScheme = ref(getColorScheme());
provide('colorScheme', colorScheme);
watch(colorScheme, val => updateColorScheme(val))
watchEffect(() => updatePageTitle(route));
</script>
<template>
+5 -6
View File
@@ -59,18 +59,17 @@ const router = createRouter({
routes
});
// set page title
router.afterEach(to => {
export const updatePageTitle = function updatePageTitle (route) {
const title =
typeof to.meta.title === 'function'
? to.meta.title(to)
: to.meta.title;
typeof route.meta.title === 'function'
? route.meta.title(route)
: route.meta.title;
if (title) {
document.title = `${title} - Seekra`;
} else {
document.title = 'Seekra';
};
});
};
export default router;