解决vue router使用history模式带参数刷新报错

前提:

Vue router默认模式为hash,url中带有#不是很美观


router配置 :

{path: '/tx/:hash?',name: 'tx',component: tx},

{path: '/address/:address?',name: 'address',component: address},


遇到的问题(均省略IP):

直接访问    /address/ 正常
通过路由访问   /address/1 正常
直接访问 (或刷新)    /address/home/1 报错


解决方案

1.在webpack.prod.conf.js配置项中加上

output: {
	// 表示在引入静态资源时,从根路径开始引入
	publicPath: '/'
},

2.config中index.js

build: {
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
}

当router模式为Hash时,1和2中的publicPath都要改为‘./’

当router模式为history时,publicPath都不需要加上点

你可能感兴趣的:(Vue.js)