106 lines
2.4 KiB
JavaScript
106 lines
2.4 KiB
JavaScript
import { createRouter, createWebHistory } from "vue-router";
|
|
// 导入所有 view 页面
|
|
import PkIndexView from "../views/pk/PkIndexView.vue";
|
|
import RanklistIndexView from "../views/ranklist/RanklistIndexView.vue";
|
|
import RecordIndexView from "../views/record/RecordIndexView.vue";
|
|
import UserBotIndexView from "../views/user/bot/UserBotIndexView.vue";
|
|
import NotFound from "../views/error/NotFound.vue";
|
|
import UserAccountLoginView from "@/views/user/account/UserAccountLoginView.vue";
|
|
import UserAccountRegisterView from "@/views/user/account/UserAccountRegisterView.vue";
|
|
// 读入 store 信息
|
|
import store from "../store/index";
|
|
|
|
// 定义所有页面的 URL 路由
|
|
const routes = [
|
|
{
|
|
path: "/",
|
|
name: "home",
|
|
// 重定向:将 home 重定向到 pk 页面
|
|
redirect: "/pk/",
|
|
// meta 存其他信息
|
|
meta: {
|
|
// 页面是否需要授权
|
|
requestAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: "/pk/",
|
|
name: "pk_index",
|
|
component: PkIndexView,
|
|
meta: {
|
|
requestAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: "/ranklist/",
|
|
name: "ranklist_index",
|
|
component: RanklistIndexView,
|
|
meta: {
|
|
requestAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: "/record/",
|
|
name: "record_index",
|
|
component: RecordIndexView,
|
|
meta: {
|
|
requestAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: "/user/bot/",
|
|
name: "user_bot_index",
|
|
component: UserBotIndexView,
|
|
meta: {
|
|
requestAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: "/user/account/login/",
|
|
name: "user_account_login",
|
|
component: UserAccountLoginView,
|
|
meta: {
|
|
requestAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: "/user/account/register/",
|
|
name: "user_account_register",
|
|
component: UserAccountRegisterView,
|
|
meta: {
|
|
requestAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: "/404/",
|
|
name: "404",
|
|
component: NotFound,
|
|
meta: {
|
|
requestAuth: false,
|
|
},
|
|
},
|
|
{
|
|
// 正则匹配所有其他非法页面到 404
|
|
path: "/:catchAll(.*)",
|
|
redirect: "/404/",
|
|
},
|
|
];
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
});
|
|
|
|
// to 表示从那个页面跳转, from 表示从哪个页面跳转出去, next 表示页面要不要执行下一步操作
|
|
router.beforeEach((to, from, next) => {
|
|
// 如果页面需要授权而且未登录,则跳转到用户登录页面
|
|
if (to.meta.requestAuth && !store.state.user.is_login) {
|
|
next({ name: "user_account_login" });
|
|
} else {
|
|
// next() 跳转到默认页面
|
|
next();
|
|
}
|
|
});
|
|
|
|
export default router;
|