在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(); } })

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2022-03-03
猜你喜欢
  • 2022-12-23
  • 2021-04-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2018-05-20
相关资源
相似解决方案