ruoyi-plus-soybean/src/router/index.ts

22 lines
679 B
TypeScript
Raw Normal View History

import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
2021-08-17 14:59:59 +08:00
import type { App } from 'vue';
import type { RouteRecordRaw } from 'vue-router';
2021-09-09 12:00:18 +08:00
import { constantRoutes, customRoutes } from './routes';
2021-08-17 14:59:59 +08:00
import createRouterGuide from './permission';
2021-09-09 12:00:18 +08:00
const routes: Array<RouteRecordRaw> = [...customRoutes, ...constantRoutes];
2021-08-17 14:59:59 +08:00
2021-09-09 12:00:18 +08:00
/** 用于部署vercel托管服务 */
const isVercel = import.meta.env.VITE_HTTP_ENV === 'VERCEL';
2021-09-09 12:00:18 +08:00
const router = createRouter({
history: isVercel ? createWebHashHistory() : createWebHistory(),
2021-08-17 14:59:59 +08:00
routes
});
2021-09-09 12:00:18 +08:00
export async function setupRouter(app: App) {
2021-08-17 14:59:59 +08:00
app.use(router);
2021-08-26 14:09:31 +08:00
createRouterGuide(router);
2021-09-09 12:00:18 +08:00
await router.isReady();
2021-08-17 14:59:59 +08:00
}