refactor: add window title support
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import { useTokenStore } from '@/stores/token'
|
import { useTokenStore } from '@/stores/token'
|
||||||
import { tokenValid as apiCommonTokenValid } from '@/api/common'
|
import { tokenValid as apiCommonTokenValid } from '@/api/common'
|
||||||
|
import { i18n } from '@/utils/i18n'
|
||||||
|
|
||||||
import Home from '@/views/Home.vue'
|
import Home from '@/views/Home.vue'
|
||||||
import Collection from '@/views/Collection.vue'
|
import Collection from '@/views/Collection.vue'
|
||||||
@@ -13,15 +14,15 @@ import Login from '@/views/Login.vue'
|
|||||||
import NotFound from '@/views/NotFound.vue'
|
import NotFound from '@/views/NotFound.vue'
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{ path: '/home', name: "Home", component: Home },
|
{ path: '/home', name: "Home", meta: { title: 'pageName-home' }, component: Home },
|
||||||
{ path: '/collection', name: "Collection", meta: { requireLoggedInCheck: true }, component: Collection },
|
{ path: '/collection', name: "Collection", meta: { title: 'pageName-collection', requireLoggedInCheck: true }, component: Collection },
|
||||||
{ path: '/calendar', name: "Calendar", meta: { requireLoggedInCheck: true }, component: Calendar },
|
{ path: '/calendar', name: "Calendar", meta: { title: 'pageName-calendar', requireLoggedInCheck: true }, component: Calendar },
|
||||||
{ path: '/todo', name: "Todo", meta: { requireLoggedInCheck: true }, component: Todo },
|
{ path: '/todo', name: "Todo", meta: { title: 'pageName-todo', requireLoggedInCheck: true }, component: Todo },
|
||||||
{ path: '/admin', name: "Admin", meta: { requireLoggedInCheck: true }, component: Admin },
|
{ path: '/admin', name: "Admin", meta: { title: 'pageName-admin', requireLoggedInCheck: true }, component: Admin },
|
||||||
|
|
||||||
{ path: '/calendar/event', name: "CalendarEventAdd", meta: { requireLoggedInCheck: true }, component: CalendarEvent },
|
{ path: '/calendar/event', name: "CalendarEventAdd", meta: { title: 'pageName-event', requireLoggedInCheck: true }, component: CalendarEvent },
|
||||||
{ path: '/calendar/event/:uuid', name: "CalendarEventUpdate", meta: { requireLoggedInCheck: true }, component: CalendarEvent },
|
{ path: '/calendar/event/:uuid', name: "CalendarEventUpdate", meta: { title: 'pageName-event', requireLoggedInCheck: true }, component: CalendarEvent },
|
||||||
{ path: '/login', name: "Login", meta: { requireLoggedOutCheck: true }, component: Login },
|
{ path: '/login', name: "Login", meta: { title: 'pageName-login', requireLoggedOutCheck: true }, component: Login },
|
||||||
|
|
||||||
{ path: '/404', name: "NotFound", component: NotFound },
|
{ path: '/404', name: "NotFound", component: NotFound },
|
||||||
|
|
||||||
@@ -55,8 +56,12 @@ router.beforeEach(async (to, _from) => {
|
|||||||
if (token.isLoggedIn) {
|
if (token.isLoggedIn) {
|
||||||
return { name: 'Default', replace: true };
|
return { name: 'Default', replace: true };
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
return true;
|
|
||||||
|
// Apply the route's window title (translated via vue-i18n). Only reached
|
||||||
|
// when the navigation is allowed — redirects short-circuit above.
|
||||||
|
if (typeof to.meta.title === 'string') {
|
||||||
|
document.title = i18n.global.t(to.meta.title)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user