-
如果路由要使用history模式当宴,需要將nigix配置為:
1.前端配置:
const router = new VueRouter({
mode: "history",
routes,
});
2.nigix配置
server {
listen 9903;
server_name localhost;
location / {
root '/root/static';
index /index.html;
try_files $uri $uri/ /index.html;
}
}
-
如果路由要使用history模式,并且想要一個(gè)根目錄下面掛多個(gè)站點(diǎn)
1.前端配置路由:
const router = new VueRouter({
mode: "history",
base: "/one/",
routes,
});
2.修改vue.config.js 的 publicPath 為自己的二級(jí)目錄即可
module.exports = {
publicPath: "/one/",
};
3.配置服務(wù)器nigx代碼:
server {
listen 9903;
server_name localhost;
root '/root/static';
//這個(gè)是通過localhost:9903/aabb/可以訪問
location /aabb {
index /index.html;
try_files $uri $uri/ /aabb/index.html;
}
//這個(gè)是通過localhost:9903/one/可以訪問
location /one {
index /index.html;
try_files $uri $uri/ /one/index.html;
}
}