vue全局路由守卫beforeEach

在main.js里使用方法 router.beforeEach((to,from,next)=>{})

to,是将要跳转的路由,

from,是离开的路由

next是个方法,判断to.path 或者 from.path ,如果符合条件,则允许跳转

 例子:

main.js

router.beforeEach((to,from,next)=>{
  if(to.path==='/about'){
    alert("登陆后方可查看")
next('/login') }
else{ next(); } })
原文地址:https://www.cnblogs.com/luguankun/p/10688686.html