//router.js加入
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
//解决刷新页面404
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes : routers
})
若后端将打包好的项目放在xxx.com/data/下,publicPath: '/data/',base使用publicPath的值,后端配置Nginx重定向到/data/index.html,增加404的路由,这样刷新页面停在当前页面,手动输入不存在的路由展示404.