使用vue-router
在vite.config.ts中配置base
base: process.env.NODE_ENV === 'development' ? '' : '/test/',
router/index.ts中配置
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes
})
打包后配置nginx.conf
server {
listen 8080;
listen [::]:8080;
server_name localhost;
#代码放在/web/test中
location /test {
root /web;
index index.html index.htm;
try_files $uri $uri/ /test/index.html;
}
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}