diff --git a/src/router/index.js b/src/router/index.js index c702868..a3a78f2 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -41,7 +41,11 @@ const routerOptions = { const router = createRouter(routerOptions); router.beforeResolve((to, from, next) => { - pageTitle(to?.meta?.title); + if (to?.meta?.title) { + pageTitle(to?.meta?.title); + } else if (to.name === 'Home') { + pageTitle(config.nazhua.title); + } next(); }); diff --git a/src/utils/page-title.js b/src/utils/page-title.js index 5d65338..3248def 100644 --- a/src/utils/page-title.js +++ b/src/utils/page-title.js @@ -1,5 +1,6 @@ import config from '@/config'; export default (...args) => { - document.title = [...args, config.nazhua.title].filter((i) => i).join(' - '); + const titles = [...new Set([...args, config.nazhua.title])].filter((i) => i); + document.title = titles.join(' - '); }; diff --git a/src/views/detail.vue b/src/views/detail.vue index a5f50b2..7e189f9 100644 --- a/src/views/detail.vue +++ b/src/views/detail.vue @@ -130,9 +130,9 @@ function handleWorldMapWidth() { ); } -watch(() => info.value, () => { - if (info.value) { - pageTitle(info.value?.Name, '节点详情'); +watch(() => info.value, (oldValue, newValue) => { + if (!oldValue && newValue && router.currentRoute.value.name === 'ServerDetail') { + pageTitle(newValue?.Name, '节点详情'); handleWorldMapWidth(); } });