forked from DebaucheryLibrarian/traxxx
Added page title function for Composition API components.
This commit is contained in:
parent
fdad61465c
commit
6de6053eaa
|
@ -8,6 +8,7 @@ import router from './router';
|
||||||
import initStore from './store';
|
import initStore from './store';
|
||||||
import initUiObservers from './ui/observers';
|
import initUiObservers from './ui/observers';
|
||||||
import initAuthObservers from './auth/observers';
|
import initAuthObservers from './auth/observers';
|
||||||
|
import setPageTitle from './set-page-title';
|
||||||
|
|
||||||
import { formatDate, formatDuration } from './format';
|
import { formatDate, formatDuration } from './format';
|
||||||
|
|
||||||
|
@ -101,12 +102,7 @@ async function init() {
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
pageTitle(title) {
|
pageTitle(title) {
|
||||||
if (title) {
|
setPageTitle(title); // for Options API components
|
||||||
document.title = `traxxx - ${title}`;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.title = 'traxxx';
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
|
|
||||||
|
import setPageTitle from './set-page-title';
|
||||||
|
|
||||||
import Home from '../components/home/home.vue';
|
import Home from '../components/home/home.vue';
|
||||||
import Login from '../components/auth/login.vue';
|
import Login from '../components/auth/login.vue';
|
||||||
import Signup from '../components/auth/signup.vue';
|
import Signup from '../components/auth/signup.vue';
|
||||||
|
@ -257,11 +259,17 @@ const routes = [
|
||||||
path: '/stats',
|
path: '/stats',
|
||||||
component: Stats,
|
component: Stats,
|
||||||
name: 'stats',
|
name: 'stats',
|
||||||
|
meta: {
|
||||||
|
title: 'Stats',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/not-found',
|
path: '/not-found',
|
||||||
name: 'not-found',
|
name: 'not-found',
|
||||||
component: NotFound,
|
component: NotFound,
|
||||||
|
meta: {
|
||||||
|
title: 'Not Found',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/:catchAll(.*)',
|
path: '/:catchAll(.*)',
|
||||||
|
@ -276,4 +284,6 @@ const router = createRouter({
|
||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.beforeEach((to) => setPageTitle(to.meta.title));
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
function setPageTitle(name) {
|
||||||
|
if (name) {
|
||||||
|
document.title = `traxxx - ${name}`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.title = 'traxxx';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default setPageTitle;
|
Loading…
Reference in New Issue