vue.config.js:
module.exports={
publicPath:"./",
outputDir:"traceweb",//打包名称
configureWebpack:config=>{
//取消console.log
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
//限制打包时chunk的最大个数10个
return{
plugins:[
new webpack.optimize,LimitchunkCountPlugin({
maxChunks:10
})
]
}
}
}
router,js
//解决路由重复点击报错的问题
const originPush = VueRouter.prototype.push
VueRouter.prototype.push=function push(location){
return originPush.call(this,location).catch(err => err)
}
VueRouter.prototype.replace=function push(location){
return originPush.call(this,location).catch(err => err)
}
Vue.use(VueRouter)
路由跳转时登录验证:
{
path:"/overview",
name:"overview",
component:(resolve)=>{
require(['../view/overview'],resolve)
},
meta:{
check:true//验证标示
}
}
//添加路由钩子
router.beforeEach((to,from,next)=>{
if(to.meta.check){
if(){//判断token vuex、sessionStorage
next()
}else{
//没token去登录,然后跳转到目的路由
next({
path:"/login",
query:{
redirect:to.fullPath
}
})
}
}else{
next()
}
})
打包时将mode设置为hash
export default new Router({
mode:'history',//history 或 hash
routes
})