美文网首页
Vue 去除路径中的#号

Vue 去除路径中的#号

作者: 魅眼ALong | 来源:发表于2020-04-24 16:09 被阅读0次

这里只列举nginx的配置,其他的配置点击这里去官网看

cli2创建的项目

先配置config/index.js,修改assetsPublicPath为根目录

module.exports = {
  build: {
      env: require('./prod.env'),
      index: path.resolve(__dirname, '../dist/index.html'),
      assetsRoot: path.resolve(__dirname, '../dist'),
      assetsSubDirectory: 'static',
      assetsPublicPath: '/',   // 重点  hash 模式会默认的在此处 添加为 assetsPublicPath: './' 打包到服务器,可正常访问,
      productionSourceMap: true,
      ...
    }
}

cli3.0

如果根目录下已有vue.config.js,,没有则新建

module.exports = {
  publicPath: '/', //部署应用时的根路径(默认'/'),也可用相对路径(存在使用限制); // 
}

然后配置nginx

    server {
        listen       80;
        server_name  hjlflat.xxxxxxx.com;
        root         E:/HY/bg/dist; 
        try_files $uri $uri/ /index.html; # 这个是重点
        #error_log    D:/Visual-NMP-x64/logs/Nginx/D__Visual-NMP-x64_www_Demo1-error.log;
        #access_log   D:/Visual-NMP-x64/logs/Nginx/D__Visual-NMP-x64_www_Demo1-access.log;       
        autoindex    on;
        index        index.html;
                       
    }

相关文章

网友评论

      本文标题:Vue 去除路径中的#号

      本文链接:https://www.haomeiwen.com/subject/obvfwhtx.html