1、先配置nginx:
location /exam {
alias /usr/local/pkg/exam/web/release/dist;
index index.html index.htm;
try_files $uri $uri/ /exam/index.html @rewrites;
}
2耻讽、在路由中添加
const router = createRouter({
history: createWebHistory('/exam/'),
routes,
})
注意如果是ts文件的話,如果默認(rèn)有生成js的話要查看對(duì)應(yīng)的js是否有加上目錄秧秉,否則設(shè)置會(huì)無(wú)效褐桌。
3、在vite.config.ts文件中添加
export default defineConfig({
base: '/exam/',
})