Vue路由History模式打包后页面空白,刷新404

 
 

项目的入口文件index.html直接在服务器访问地址的根目录下,即项目独占一个端口

vue中配置保持不变
nginx中配置如下:
server {
        listen      8899;
        server_name localhost;
        location / {
	       try_files $uri $uri/ /index.html;
        }
    }

  

 第二种就是
 
# 打包配置 config-index.js 修改路径:
 
assetsPublicPath: './';

# 前端路由配置 router.js:

const router = new VueRouter({
    mode: 'history',
    base: '/hello',
    routes
})
这里一定要一个加一个base;与项目子级目录名同步
 

nginx 配置:
server {
    listen 8088;
    server_name xxx.com;  # localhost修改为您证书绑定的域名。

    
    location / {
    }

    location /hello{
        try_files $uri $uri/ /hello/index.html;
    }
}

  

 以上只是针对项目放在子级目录的情况,刷新404的问题待解决

猜你喜欢

转载自www.cnblogs.com/lan-cheng/p/12127620.html