Files
lucia-frontend/src/router/index.ts
2026-03-07 20:03:19 +08:00

185 lines
5.6 KiB
TypeScript

// The Lucia project.
// Copyright 2023-2026 DSP, inc. All rights reserved.
// Authors:
// chiayin.kuo@dsp.im (chiayin), 2023/1/31
// imacat.yang@dsp.im (imacat), 2023/9/23
// cindy.chang@dsp.im (Cindy Chang), 2024/5/30
/**
* @module router Vue Router configuration with route definitions,
* navigation guards, and authentication redirect logic.
*/
import { createRouter, createWebHistory, } from "vue-router";
import AuthContainer from '@/views/AuthContainer.vue';
import MainContainer from '@/views/MainContainer.vue';
import Login from '@/views/Login/Login.vue';
import Files from '@/views/Files/Files.vue';
import Upload from '@/views/Upload/index.vue';
import Map from '@/views/Discover/Map/Map.vue';
import Conformance from '@/views/Discover/Conformance/index.vue';
import Performance from '@/views/Discover/Performance/index.vue';
import CompareDashboard from '@/views/Compare/Dashboard/Compare.vue';
import MapCompare from '@/views/Compare/MapCompare.vue';
import AccountAdmin from '@/views/AccountManagement/AccountAdmin/AccountAdmin.vue';
import MyAccount from '@/views/AccountManagement/MyAccount.vue';
import MemberArea from '@/views/MemberArea/index.vue';
import NotFound404 from '@/views/NotFound404.vue';
const routes = [
{
path: '/', // Default entry route
redirect: '/files', // Redirect to /files
},
{
path: '/',
name: "AuthContainer",
component: AuthContainer,
children: [
{
path: "/login",
name: "Login",
component: Login,
},
]
},
{
path: "/",
name: "MainContainer",
component: MainContainer,
meta: {
title: "MainContainer",
requiresAuth: true
},
children: [
{
path: "/member-area",
name: "MemberArea",
component: MemberArea,
},
{
path: "/files",
name: "Files",
component: Files,
},
{
path: "/account",
name: "Account Management",
children: [
{
path: "/account-admin",
name: "AcctAdmin",
component: AccountAdmin,
},
]
},{
path: "/my-account",
name: "My Account",
component: MyAccount,
},
{
path: "/upload", // router.push({ replace: true }) does not add the path to history
name: "Upload",
component: Upload
},
{
path: "/discover",
name: "Discover",
children: [
{
// type: log | filter, the parameter can be either.
// fileId: log_id | filter_id, the parameter can be either.
path: "/discover/:type/:fileId/map",
name: "Map",
component: Map,
},
{
// type: log | filter, the parameter can be either.
// fileId: log_id | filter_id, the parameter can be either.
path: "/discover/:type/:fileId/conformance",
name: "Conformance",
component: Conformance,
},
{
// type: log | filter, the parameter can be either.
// fileId: log_id | filter_id, the parameter can be either.
path: "/discover/:type/:fileId/performance",
name: "Performance",
component: Performance,
},
{
// type: log | filter, the parameter can be either.
// fileId: check_id, fetches parent data via `/log-checks/{check_id}`
path: "/discover/conformance/:type/:fileId/map",
name: "CheckMap",
component: Map,
meta: {
file: {}, // parent log or parent filter
}
},
{
// type: log | filter, the parameter can be either.
// fileId: check_id, fetches parent data via `/log-checks/{check_id}`
path: "/discover/conformance/:type/:fileId/conformance",
name: "CheckConformance",
component: Conformance,
meta: {
file: {}, // parent log or parent filter
}
},
{
// type: log | filter, the parameter can be either.
// fileId: check_id, fetches parent data via `/log-checks/{check_id}`
path: "/discover/conformance/:type/:fileId/performance",
name: "CheckPerformance",
component: Performance,
meta: {
file: {}, // parent log or parent filter
}
},
]
},
{
path: "/compare",
name: "Compare",
children: [
{
path: "/compare/dashboard/:primaryType/:primaryId/:secondaryType/:secondaryId",
name: "CompareDashboard",
component: CompareDashboard,
}, {
path: "/compare/map/:primaryType/:primaryId/:secondaryType/:secondaryId",
name: "MapCompare",
component: MapCompare,
}
]
},
]
},
{
path: "/:pathMatch(.*)*",
name: "NotFound404",
component: NotFound404,
},
];
const base_url = import.meta.env.BASE_URL;
const router = createRouter({
history: createWebHistory(base_url), //(/)
// history: createWebHashHistory(base_url), // (/#)
routes
});
// Global navigation guard
router.beforeEach((to, from) => {
// to: Route: the target route object being navigated to
// from: Route: the current route being navigated away from
// When navigating to the login page, redirect to Files if already logged in
if (to.name === 'Login') {
const isLoggedIn = document.cookie.split(';').some(c => c.trim().startsWith('isLuciaLoggedIn='));
if (isLoggedIn) return { name: 'Files' };
}
});
export default router;