Vue.js入门(10)路由、路由嵌套、钩子函数

序言

https://router.vuejs.org/zh/

嵌套路由

子路由

路由重定向

路由占位符

路由钩子函数有三种:

            1:全局钩子: beforeEach、 afterEach

            2:单个路由里面的钩子:  beforeEnter、 beforeLeave

            3:组件路由:beforeRouteEnter、 beforeRouteUpdate、 beforeRouteLeave

路由参数

{ path: '/user/:id', component: User, props: true },
{ path: '/user/:id', component: User, props: { uname: 'lisi', age: 20 } },
{
     path: '/user/:id',
     component: User,
     props: route => ({ uname: 'zs', age: 20, id: route.params.id })
 },
props: ['id', 'uname', 'age'],

路由导航守卫

全局守卫

路由独享守卫

this.$store.commit('UPDATE_TABBAR_STATUS', 'help-center');
this.$router.push({ name: 'setPassWord', query: { hotelStaffType: 'hotel' } });

获取路由参数

1.通过query配置的:this.$route.query

 this.action = this.$route.query.action
    if (this.action === 'add') {
      this.title = '新建角色'
    } else if (this.action === 'edit') {
      this.title = '修改角色'
    }

2.通过params配置的:this.$route.params

 

回退到上一步
this.$router.back(-1)
 

 

资料

超详细!Vue-Router手把手教程

posted @   ~沐风  阅读(141)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示