fix: site path and use history router (#382)

This commit is contained in:
yuyang 2022-12-28 15:12:28 +08:00 committed by GitHub
parent c9d06f103b
commit 573efe6cd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 2 deletions

3
.env.site Normal file
View File

@ -0,0 +1,3 @@
VITE_SOME_KEY=123
# 打包路径 根据项目不同按需配置
VITE_BASE_URL = https://static.tdesign.tencent.com/starter/vue-next/

View File

@ -7,6 +7,7 @@
"dev:linux": "vite --mode development",
"build:test": "vite build --mode test",
"build": "vue-tsc --noEmit && vite build --mode release",
"build:site": "vue-tsc --noEmit && vite build --mode site",
"preview": "vite preview",
"lint": "eslint --ext .vue,.js,.jsx,.ts,.tsx ./ --max-warnings 0",
"lint:fix": "eslint --ext .vue,.js,jsx,.ts,.tsx ./ --max-warnings 0 --fix",

View File

@ -18,4 +18,10 @@ export default {
// 正式环境 cdn 路径
cdn: '',
},
site: {
// TDesign部署特殊需要 与release功能一致
host: 'https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com',
// 正式环境 cdn 路径
cdn: '',
},
};

View File

@ -1,6 +1,8 @@
import { useRoute, createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { useRoute, createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import uniq from 'lodash/uniq';
const env = import.meta.env.MODE || 'development';
// 自动导入modules文件夹下所有ts文件
const modules = import.meta.globEager('./modules/**/*.ts');
@ -8,6 +10,7 @@ const modules = import.meta.globEager('./modules/**/*.ts');
const routeModuleList: Array<RouteRecordRaw> = [];
Object.keys(modules).forEach((key) => {
// @ts-ignore
const mod = modules[key].default || {};
const modList = Array.isArray(mod) ? [...mod] : [mod];
routeModuleList.push(...modList);
@ -70,7 +73,7 @@ export const getActive = (maxLevel = 3): string => {
};
const router = createRouter({
history: createWebHashHistory(),
history: createWebHistory(env === 'site' ? '/starter/vue-next/' : null),
routes: allRoutes,
scrollBehavior() {
return {