老师,请问,如果要在这里怎么加beforeEnter中的逻辑??

老师,请问,如果要在这里怎么加beforeEnter中的逻辑??

router.beforeEach((to, from, next) => {

  const isLogin = localStorage.isLogin

  if (isLogin || to.name === 'Login') {

    next()

  } else {

    next({ name: 'Login' })

  }

  next()

})


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,直接写在router.beforeEach((to, from, next) => { // 需要处理的逻辑写在这里即可}

祝学习愉快!

  • router.beforeEach((to, from, next) => {

      const isLogin = localStorage.isLogin

      if (isLogin || to.name === 'Login') {

        if (isLogin || to.name === 'Home') {

          next({ name: 'Home' })

        }

      } else {

        next({ name: 'Login' })

      }

    })


    老师 帮我看看我这个代码为啥出错 在这里面加跳转

    2023-08-25 09:48:15
  • 同学教学服务期已经过期了,老师这边已经不能在继续为你答疑服务了。同学可以通过查看问答区,去找一下相似的问题解答作参考。或者可以选择增加服务期如下:

    https://img1.sycdn.imooc.com//climg/64e81262099ede2e08370423.jpg

    祝学习愉快!

    2023-08-25 10:27:24
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师