beforeEach路由前置守卫传全局参数

使用全局路由前置守卫(to是跳转后的页面路由,from是跳转前的,next是必须要执行的,加上next路由才会跳转)

注意: 不能直接执行next({参数}),会进入死循环
正确写法如图所示,加个判断再用next传参

router.beforeEach((to, from, next) => {
	if(to.query.time == undefined){
		let toQuery = JSON.parse(JSON.stringify(to.query));
		toQuery.time = new Date().getTime()
		next({
            path: to.path,
            query: toQuery
        })
	}else{
		next()
	}
})

你可能感兴趣的:(基于Vue的功能)