Issue #151: Done.

This commit is contained in:
chiayin
2023-10-17 15:52:38 +08:00
parent c85b7f2d71
commit 85d1f9a487
4 changed files with 72 additions and 21 deletions

View File

@@ -80,11 +80,11 @@ const router = createRouter({
router.beforeEach((to, from) => {
// to: Route: 即將要進入的目標 路由物件
// from: Route: 當前導航正要離開的路由
let isCookie = document.cookie.split(';').some(c => c.trim().startsWith('luciaToken=')); // 是否登入
let isRemoveCookie = document.cookie.split(';').some(c => c.trim().startsWith('expires=Thu, 01 Jan 1970 00:00:00 UTC;')); // 是否登入,有到期日表示已登出。
// 當路由到 login 時有登入要跳轉至home
if (to.name === 'Login') {
if (isCookie) router.push({ name: 'Files' });
if (isRemoveCookie) router.push({ name: 'Files' });
}
});