1111
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
const LoginView = () => import("@/views/LoginView.vue");
|
||||
const MainLayout = () => import("@/components/layout/MainLayout.vue");
|
||||
const LiveRoomsView = () => import("@/views/LiveRoomsView.vue");
|
||||
const RecordTasksView = () => import("@/views/RecordTasksView.vue");
|
||||
const RecordTaskDetailView = () => import("@/views/RecordTaskDetailView.vue");
|
||||
const LogsView = () => import("@/views/LogsView.vue");
|
||||
const SettingsView = () => import("@/views/SettingsView.vue");
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: LoginView,
|
||||
meta: { anonymous: true }
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
component: MainLayout,
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
redirect: "/live-rooms"
|
||||
},
|
||||
{
|
||||
path: "live-rooms",
|
||||
name: "live-rooms",
|
||||
component: LiveRoomsView
|
||||
},
|
||||
{
|
||||
path: "record-tasks",
|
||||
name: "record-tasks",
|
||||
component: RecordTasksView
|
||||
},
|
||||
{
|
||||
path: "record-tasks/:id",
|
||||
name: "record-task-detail",
|
||||
component: RecordTaskDetailView,
|
||||
props: true
|
||||
},
|
||||
{
|
||||
path: "logs",
|
||||
name: "logs",
|
||||
component: LogsView
|
||||
},
|
||||
{
|
||||
path: "settings",
|
||||
name: "settings",
|
||||
component: SettingsView
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
router.beforeEach((to) => {
|
||||
const authStore = useAuthStore();
|
||||
|
||||
if (!to.meta.anonymous && !authStore.isAuthenticated) {
|
||||
return { name: "login" };
|
||||
}
|
||||
|
||||
if (to.name === "login" && authStore.isAuthenticated) {
|
||||
return { name: "live-rooms" };
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user