美文网首页
Vue-cli3 使用history模式(去掉#)

Vue-cli3 使用history模式(去掉#)

作者: 取个帅气的名字真好 | 来源:发表于2019-04-18 13:41 被阅读0次

1、在router中设置

VUE_APP_SRC='/xxx'

  mode: "history",
  base: process.env.VUE_APP_SRC, 
  • process.env.VUE_APP_SRC为线上环境的某个路径,一个域名对应多个vue.js工程必须要用

2、vue.config.js 设置publicPath

module.exports = {
// 默认'/',部署应用包时的基本 URL  history 本地使用默认值 '/'
//注:在本地一定要用 '/',否则二级路由刷新找不到js路径
//IS_PROD是判断是否为现上环境,可自行配置,process.env.VUE_APP_SRC为线上环境的某个路径。
  publicPath: IS_PROD ? process.env.VUE_APP_SRC : '/',
}

完成以上足以解决

Uncaught SyntaxError: Unexpected token <

后台Nginx

location / {
  try_files $uri $uri/ /index.html;
}
location /xxx/ {
  index index.html index.htm;
  try_files $uri $uri/ /xxx/index.html break;
 }


相关文章

网友评论

      本文标题:Vue-cli3 使用history模式(去掉#)

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