如果要加前缀,三者要保持一致。
一、配置含义
publicPath是控制静态资源访问路径。
router的base是控制路由跳转前缀。
nginx是控制静态资源放在服务器的位置,反向代理。
二、配置详情
类型 | 配置 | 实际对应地址 | |
publicPath | publicPath:'/bbb/' | http://localhost:8080/bbb/static/js/7.js | |
router | base: '/bbb/', | http://localhost:8080/bbb/servicePackage | |
nginx | location /bbb/ | http://localhost:8080/bbb/ |
例如,域名aaa.com.cn,访问前缀为bbb
- publickPath:‘/bbb’ 。实际静态资源路径比如http://localhost:8080/bbb/static/js/7.js
- router 。实际路由跳转 http://localhost:8080/bbb/serve http://localhost:8080/bbb/price
const router = new VueRouter({
mode: 'history',
base: '/bbb/',
routes,
})
nginx
location /bbb/ {
alias D:/mySelf/daima/vue/hppm-vue/dist/;
# root html;
index index.html index.htm 表单设计.htm;
try_files $uri $uri/ /html/hppm/index.html;
}
三、原因
- publicPath:设置成/bbb/,就表示绝对地址,在根目录下面的/bbb/,访问对应static中静态资源。如果配置“./”,也是可以的,表示相对路径,当前路径下的静态资源,因为nginx和router配置了相同的,所以对应路径的静态资源肯定能找到。
- router:路由跳转有统一的前缀,这样就能对应上nginx的地址,找到对应的页面。
- nginx:/bbb/,根目录不一定有bbb,一般会将项目放在统一固定地方,所以反向代理指一下。
版权声明:本文为qq_42440919原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。