Vue3学习笔记2——路由守卫

路由守卫

全局

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

组件内守卫

  • beforeRouteEnter((to, from, next) => {})
  • beforeRouteUpdate((to, from, next) => {})
  • beforeRouteLeave((to, from, next) => {})

路由独享

  • beforeEnter((to, from, next) => {})

参数详解

参数 描述
to 跳转到哪个路由对象
from 要离开的路由对象
next 一个方法,可以接收参数。这个方法必须调用,不使用无法跳转
  • next():要to过去
  • next(false):可以不通过,中断跳转
  • next('/'):不让过,可以去另一个地方
相关推荐
excel4 分钟前
🔍 Vue 模板编译中的资源路径转换机制:transformAssetUrl 深度解析
前端
excel7 分钟前
Vue 模板编译中的 srcset 机制详解:从 HTML 语义到编译器实现
前端
excel7 分钟前
🌐 从 Map 到 LRUCache:构建智能缓存工厂函数
前端
excel8 分钟前
Vue 模板编译中的资源路径转换:transformSrcset 深度解析
前端
excel16 分钟前
Vue 工具函数源码解析:URL 解析与分类逻辑详解
前端
excel18 分钟前
Vue SFC 样式预处理器(Style Preprocessor)源码解析
前端
excel20 分钟前
深度解析:Vue Scoped 样式编译原理 —— vue-sfc-scoped 插件源码详解
前端
excel22 分钟前
Vue SFC Trim 插件源码解析:自动清理多余空白的 PostCSS 实现
前端
excel25 分钟前
Vue SFC 样式变量机制源码深度解析:cssVarsPlugin 与编译流程
前端
excel28 分钟前
🧩 Vue 编译工具中的实用函数模块解析
前端