下面两种路径,一种可以,另一种会出现找不到文件错误
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;
}
是否还需要其他配置,谢谢🙏
配置上没看出什么问题
能截个图么?
nginx配置如下:

错误如下:
图1:

图2:

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 谢谢啦 ~~~~
Most helpful comment
@baselin 你好,找到问题了,不是nginx问题,上面的配置是对的。
当换成history模式,可能引用路径和hash # 是不一样的。
这里修改config文件夹下的index.js,原来:
修改后:
主要问题出在这里,重新打包、部署,测试可行。问题关闭啦。