feat: 实现管理后台 W1-W3 假数据界面
This commit is contained in:
+35
-3
@@ -1,13 +1,45 @@
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import HomeView from "../views/HomeView.vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
export const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: () => import("../views/LoginView.vue"),
|
||||
meta: { public: true },
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
name: "home",
|
||||
component: HomeView,
|
||||
component: () => import("../layouts/AdminLayout.vue"),
|
||||
children: [
|
||||
{ path: "", redirect: "/overview" },
|
||||
{ path: "overview", name: "overview", component: () => import("../views/OverviewView.vue") },
|
||||
{ path: "endpoints", name: "endpoints", component: () => import("../views/EndpointsView.vue") },
|
||||
{ path: "registration", name: "registration", component: () => import("../views/RegistrationView.vue") },
|
||||
{ path: "groups", name: "groups", component: () => import("../views/GroupsView.vue") },
|
||||
{ path: "messages", name: "messages", component: () => import("../views/MessagesView.vue") },
|
||||
{ path: "tokens", name: "tokens", component: () => import("../views/TokensView.vue") },
|
||||
{ path: "settings", name: "settings", component: () => import("../views/SettingsView.vue") },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
router.beforeEach(async (to) => {
|
||||
const auth = useAuthStore();
|
||||
if (!auth.ready) {
|
||||
await auth.hydrate();
|
||||
}
|
||||
if (to.meta.public) {
|
||||
if (auth.isLoggedIn && to.name === "login") {
|
||||
return { name: "overview" };
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!auth.isLoggedIn) {
|
||||
return { name: "login", query: { redirect: to.fullPath } };
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user