Vue-element-admin: 生产环境assetsPublicPat与staticPath调整

Created on 5 May 2017  ·  8Comments  ·  Source: PanJiaChen/vue-element-admin

下面两种路径,一种可以,另一种会出现找不到文件错误
http://xxx.com/dashboard 正常访问
http://xxx.com/introduction/index 找不到js

我在build之后,nginx的配置如下:
listen 80;
server_name xxx.com;
location / {
root /home/ubuntu/vue-demo/dist;
index index.html;
try_files $uri $uri/ /index.html =404;
}

是否还需要其他配置,谢谢🙏

Most helpful comment

@baselin 你好,找到问题了,不是nginx问题,上面的配置是对的。

当换成history模式,可能引用路径和hash # 是不一样的。
这里修改config文件夹下的index.js,原来:

assetsPublicPath: './',
staticPath:'./',

修改后:

assetsPublicPath: '/',
staticPath:'/',

主要问题出在这里,重新打包、部署,测试可行。问题关闭啦。

All 8 comments

配置上没看出什么问题
能截个图么?

nginx配置如下:
15f7ba05-3ae0-4316-9efa-cc791de227b7

错误如下:
图1:
b8551af4-3dfd-4acb-bbe3-0d0ce141bd63
图2:
1f40dfb6-9c72-4fc5-b22a-69f6fb615efc

introduction/js 是什么 哪来的。。。

原本的页面“简述” http://localhost:9528/#/introduction/index
我只是把#去掉了,在router的mode这里,改成了history。
export default new Router({
mode: 'history',

js所有文件都在dist/js文件夹下面,但是URL如果是localhost:9528/introduction/index等localhost:9528/###/*格式,网页会去dist的###文件夹下找js,这就导致不对。我估计

不是说去掉#号history模式需要node配合吗?vue官方的配置也是这种错误,搞了一天nginx配置都不行,你们有谁配置成功了告诉我一下谢谢~

@baselin 你好,找到问题了,不是nginx问题,上面的配置是对的。

当换成history模式,可能引用路径和hash # 是不一样的。
这里修改config文件夹下的index.js,原来:

assetsPublicPath: './',
staticPath:'./',

修改后:

assetsPublicPath: '/',
staticPath:'/',

主要问题出在这里,重新打包、部署,测试可行。问题关闭啦。

@YuxinChou 谢谢啦 ~~~~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sunchenguang picture sunchenguang  ·  4Comments

eladcandroid picture eladcandroid  ·  4Comments

TianYouH picture TianYouH  ·  4Comments

hfengshan picture hfengshan  ·  4Comments

evan-lin9 picture evan-lin9  ·  4Comments