假设我有2条路由/
和/first
,并且都应该路由到不同的vue应用。
我的根切换正常,问题是当您转到/first
时,vue应用无法加载任何javascript文件或css文件,因为它们转到了/js
或/css
而不是/first/js
或/first/css
我拥有的两个位置块非常简单,如下所示:
location /first {
alias /home/first/dist;
index index.html index.htm;
}
location / {
alias /home/second/dist;
index index.html index.htm;
}
js和css文件的加载方式通常与/js/chunk-vendors.deb8a740.js
类似。我之所以这样说不起作用,是因为nginx在响应中剥离了/first
,因为如果我将导入更改为/first/js/chunk-vendors.deb8a740.js
,则应用会加载。
我至少能够针对自己的情况解决此问题,所以我将分享最终的结果。
我添加了包含公共路径的vue.config.js
,因此dist文件夹中的所有导入都从/js
变为/first/js
我的案子只需要什么。
module.exports = {
publicPath: '/first/'
}