如果tofrom是相同的,那么这段代码会一直执行,直到超出浏览器的最大调用堆栈大小,导致页面崩溃。因为在这段代码中,没有判断tofrom是否相同的条件,所以会一直循环执行router.beforeEach钩子函数。为了避免这种情况,可以在beforeEach钩子函数中添加一个判断条件,如果tofrom相同,则直接调用next()函数,跳过这个钩子函数的执行。例如:

router.beforeEach((to, from, next) => {
  if (to.path === from.path) {
    next()
    return
  }

  // 其他代码...
})
routerbeforeEachto from next = consolelogtofromnexttofromnext11111111111111111 NProgressstart start progress bar if VuelsgetACCESS_TOKEN && whiteListindexOftopath == -1 has token if topa

原文地址: https://www.cveoy.top/t/topic/hHD5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录