generated from Seekra/repository-template
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:
+5
-1
@@ -18,8 +18,12 @@ limitations under the License.
|
|||||||
import Navbar from './features/nav/components/Navbar.vue';
|
import Navbar from './features/nav/components/Navbar.vue';
|
||||||
import Footer from './features/footer/components/Footer.vue';
|
import Footer from './features/footer/components/Footer.vue';
|
||||||
|
|
||||||
|
import { updatePageTitle } from './router';
|
||||||
import { useColorScheme } from './features/colorScheme/composables/useColorScheme';
|
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 { getColorScheme, updateColorScheme } = useColorScheme();
|
||||||
const colorScheme = ref(getColorScheme());
|
const colorScheme = ref(getColorScheme());
|
||||||
|
|||||||
+5
-6
@@ -59,18 +59,17 @@ const router = createRouter({
|
|||||||
routes
|
routes
|
||||||
});
|
});
|
||||||
|
|
||||||
// set page title
|
export const updatePageTitle = function updatePageTitle (route) {
|
||||||
router.afterEach(to => {
|
|
||||||
const title =
|
const title =
|
||||||
typeof to.meta.title === 'function'
|
typeof route.meta.title === 'function'
|
||||||
? to.meta.title(to)
|
? route.meta.title(route)
|
||||||
: to.meta.title;
|
: route.meta.title;
|
||||||
|
|
||||||
if (title) {
|
if (title) {
|
||||||
document.title = `${title} - Seekra`;
|
document.title = `${title} - Seekra`;
|
||||||
} else {
|
} else {
|
||||||
document.title = 'Seekra';
|
document.title = 'Seekra';
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
Reference in New Issue
Block a user