基于多个vue应用程序的路径的Nginx根交换机

问题描述 投票:0回答:1

假设我有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.js nginx nginx-location nginx-config
1个回答
0
投票

我至少能够针对自己的情况解决此问题,所以我将分享最终的结果。

我添加了包含公共路径的vue.config.js,因此dist文件夹中的所有导入都从/js变为/first/js

我的案子只需要什么。

module.exports = {
    publicPath: '/first/'
}
© www.soinside.com 2019 - 2024. All rights reserved.