修复网页端未知路径跳转逻辑

This commit is contained in:
2026-09-05 23:37:13 +08:00
parent 9ac56115d0
commit 852a715722
2 changed files with 14 additions and 9 deletions
+2 -1
View File
@@ -14,6 +14,7 @@ const pageNames = [
] as const ] as const
const routes = [ const routes = [
{ path: '/', redirect: '/admin' },
{ path: '/admin/login', name: 'admin-login', component: () => import('../views/admin/AdminLoginView.vue'), meta: { requiresAuth: false, isAdmin: true, hideNav: true } }, { path: '/admin/login', name: 'admin-login', component: () => import('../views/admin/AdminLoginView.vue'), meta: { requiresAuth: false, isAdmin: true, hideNav: true } },
{ {
path: '/admin', component: () => import('../views/admin/AdminLayout.vue'), meta: { requiresAuth: true, isAdmin: true, hideNav: true }, path: '/admin', component: () => import('../views/admin/AdminLayout.vue'), meta: { requiresAuth: true, isAdmin: true, hideNav: true },
@@ -21,7 +22,7 @@ const routes = [
path, name, component: () => import(`../views/admin/${view}.vue`), meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode } path, name, component: () => import(`../views/admin/${view}.vue`), meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode }
})) }))
}, },
{ path: '/:pathMatch(.*)*', name: 'not-found', component: () => import('../views/NotFoundView.vue'), meta: { requiresAuth: false, isAdmin: true, hideNav: true } } { path: '/:pathMatch(.*)*', name: 'not-found', component: () => import('../views/NotFoundView.vue'), meta: { requiresAuth: false, isAdmin: false, hideNav: true } }
] ]
const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes }) const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes })
+12 -8
View File
@@ -12,11 +12,11 @@
<span class="not-found-kicker">{{ BRAND_CONFIG.appName }}</span> <span class="not-found-kicker">{{ BRAND_CONFIG.appName }}</span>
<div class="error-code">404</div> <div class="error-code">404</div>
<h1>这页去做护理了</h1> <h1>这页去做护理了</h1>
<p>您访问的页面不存在或已被删除,我们带您回到首页继续浏览作品。</p> <p>您访问的页面不存在或已被删除,我们将在 5 秒后返回上一页。</p>
<p class="redirect-message"> <p class="redirect-message">
将在 <span class="countdown">{{ countdown }}</span> 秒后自动跳转到首页... 将在 <span class="countdown">{{ countdown }}</span> 秒后返回上一页...
</p> </p>
<a-button type="primary" @click="redirectToHome">立即前往首页</a-button> <a-button type="primary" @click="handleBackClick">返回上一页</a-button>
</div> </div>
</div> </div>
</template> </template>
@@ -53,16 +53,20 @@ const handleBackClick = () => {
router.back() router.back()
return return
} }
router.push('/home') router.replace('/admin/login')
} }
/** redirectToHome is a local helper used by this page script. */ /** redirectToLogin 将无历史来源的访问导回管理端登录页。 */
const redirectToHome = () => { const redirectToLogin = () => {
clearRedirectTimer() clearRedirectTimer()
router.push('/home') router.replace('/admin/login')
} }
onMounted(() => { onMounted(() => {
if (window.history.length <= 1) {
redirectToLogin()
return
}
timer = window.setInterval(() => { timer = window.setInterval(() => {
if (countdown.value > 0) { if (countdown.value > 0) {
countdown.value-- countdown.value--
@@ -70,7 +74,7 @@ onMounted(() => {
if (timer) { if (timer) {
clearInterval(timer) clearInterval(timer)
} }
redirectToHome() handleBackClick()
} }
}, 1000) }, 1000)
}) })