라우터 afterEach에서 가장 깊은 meta.titleKey 사용, locale 변경 watch에서 동일 로직으로 재계산, 초기 진입 시 common.app.title로 교체. docs에 검증 기록 추가.
156 lines
6.2 KiB
JavaScript
156 lines
6.2 KiB
JavaScript
import Vue from 'vue'
|
|
import VueRouter from 'vue-router'
|
|
import store from '@/store';
|
|
import i18n from '@/i18n'
|
|
|
|
import DefaultLayout from '@/layouts/default'
|
|
|
|
Vue.use(VueRouter)
|
|
|
|
// route level code-splitting
|
|
// this generates a separate chunk (about.[hash].js) for this route
|
|
// which is lazy-loaded when the route is visited.
|
|
const routes = [
|
|
{
|
|
path: '/',
|
|
name: 'DefaultLayout',
|
|
component: DefaultLayout,
|
|
children: [
|
|
{
|
|
path: '/content/list',
|
|
name: 'ContentList',
|
|
component: () => import(/* webpackChunkName: "content" */ '../views/Content/ContentList.vue')
|
|
},
|
|
{
|
|
path: '/agent/creators',
|
|
name: 'AgentCreators',
|
|
component: () => import(/* webpackChunkName: "agent" */ '../views/Agent/Creators.vue')
|
|
},
|
|
// Agent-only calculate routes (placeholders)
|
|
{
|
|
path: '/agent/calculate/live',
|
|
name: 'AgentCalculateLive',
|
|
component: () => import(/* webpackChunkName: "agent-calc" */ '../views/Agent/Calculate/AgentCalculateLive.vue')
|
|
},
|
|
{
|
|
path: '/agent/calculate/content-by-date',
|
|
name: 'AgentCalculateContent',
|
|
component: () => import(/* webpackChunkName: "agent-calc" */ '../views/Agent/Calculate/AgentCalculateContent.vue')
|
|
},
|
|
{
|
|
path: '/agent/calculate/content-donation-by-date',
|
|
name: 'AgentCalculateContentDonation',
|
|
component: () => import(/* webpackChunkName: "agent-calc" */ '../views/Agent/Calculate/AgentCalculateContentDonation.vue')
|
|
},
|
|
{
|
|
path: '/agent/calculate/community-post',
|
|
name: 'AgentCalculateCommunityPost',
|
|
component: () => import(/* webpackChunkName: "agent-calc" */ '../views/Agent/Calculate/AgentCalculateCommunityPost.vue')
|
|
},
|
|
{
|
|
path: '/agent/calculate/channel-donation',
|
|
name: 'AgentCalculateChannelDonation',
|
|
component: () => import(/* webpackChunkName: "agent-calc" */ '../views/Agent/Calculate/AgentCalculateChannelDonation.vue')
|
|
},
|
|
{
|
|
path: '/content/category/list',
|
|
name: 'ContentCategoryList',
|
|
component: () => import(/* webpackChunkName: "content" */ '../views/Content/ContentCategoryList.vue')
|
|
},
|
|
{
|
|
path: '/content/series/list',
|
|
name: 'ContentSeriesList',
|
|
component: () => import(/* webpackChunkName: "content" */ '../views/Content/ContentSeriesList.vue')
|
|
},
|
|
{
|
|
path: '/content/series/detail',
|
|
name: 'ContentSeriesDetail',
|
|
component: () => import(/* webpackChunkName: "content" */ '../views/Content/ContentSeriesDetail.vue')
|
|
},
|
|
{
|
|
path: '/calculate/live',
|
|
name: 'CalculateLive',
|
|
component: () => import(/* webpackChunkName: "calculate" */ '../views/Calculate/CalculateLive.vue')
|
|
},
|
|
{
|
|
path: '/calculate/content-by-date',
|
|
name: 'CalculateContent',
|
|
component: () => import(/* webpackChunkName: "calculate" */ '../views/Calculate/CalculateContent.vue')
|
|
},
|
|
{
|
|
path: '/calculate/content-accumulation',
|
|
name: 'CalculateAccumulation',
|
|
component: () => import(/* webpackChunkName: "calculate" */ '../views/Calculate/CalculateAccumulation.vue')
|
|
},
|
|
{
|
|
path: '/calculate/content-donation-by-date',
|
|
name: 'CalculateContentDonation',
|
|
component: () => import(/* webpackChunkName: "calculate" */ '../views/Calculate/CalculateContentDonation.vue')
|
|
},
|
|
{
|
|
path: '/calculate/community-post',
|
|
name: 'CalculateCommunityPost',
|
|
component: () => import(/* webpackChunkName: "calculate" */ '../views/Calculate/CalculateCommunityPost.vue')
|
|
},
|
|
{
|
|
path: '/calculate/channel-donation',
|
|
name: 'CalculateChannelDonation',
|
|
component: () => import(/* webpackChunkName: "calculate" */ '../views/Calculate/CalculateChannelDonation.vue')
|
|
},
|
|
{
|
|
path: '/signature',
|
|
name: 'SignatureManagement',
|
|
component: () => import(/* webpackChunkName: "signature" */ '../views/Signature/SignatureManagement.vue'),
|
|
meta: { titleKey: 'view.signature.title' }
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import(/* webpackChunkName: "login" */ '../views/Login/Login.vue')
|
|
},
|
|
]
|
|
|
|
const router = new VueRouter({
|
|
mode: 'history',
|
|
base: process.env.BASE_URL,
|
|
routes
|
|
})
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.path !== '/login') {
|
|
if (to.path === '/content/series/list') {
|
|
document.documentElement.classList.add('noscroll'); // html에 클래스 추가
|
|
} else {
|
|
document.documentElement.classList.remove('noscroll');
|
|
}
|
|
|
|
const isAuthenticated = store.getters['accountStore/isAuthenticated']
|
|
if (isAuthenticated) {
|
|
next();
|
|
} else {
|
|
next('/login?redirect=' + to.fullPath)
|
|
}
|
|
} else {
|
|
next()
|
|
}
|
|
})
|
|
|
|
// 라우트 변경 시 문서 타이틀을 i18n으로 갱신
|
|
router.afterEach((to) => {
|
|
try {
|
|
// 가장 깊은 매칭 라우트에서 titleKey 탐색
|
|
const matched = (to && to.matched) ? to.matched : []
|
|
const deepest = matched.length ? matched[matched.length - 1] : to
|
|
const key = deepest && deepest.meta && deepest.meta.titleKey
|
|
const appTitle = i18n && typeof i18n.t === 'function' ? i18n.t('common.app.title') : 'Soda Admin'
|
|
const localized = key ? i18n.t(key) : ''
|
|
document.title = key ? `${localized} - ${appTitle}` : `${appTitle}`
|
|
} catch (e) {
|
|
// ignore
|
|
}
|
|
})
|
|
|
|
export default router
|