Vue3(撩课学院)笔记08-路由前置守卫,路由前置守卫设置元信息,路由后置守卫,keep-alive,一个路由tabbar案例,promise基本使用,链式调用,优化

1、路由全局前置守卫

对符合条件的路由路径进行判断并决定是否放心
Router/index.js

//引入路由
import {
   createRouter,createWebHashHistory} from 'vue-router'
import Home from './../components/Home.vue'
import Mine from './../components/Mine.vue'
import News from './../components/News.vue'
import MineMsg from './../components/MineMsg.vue'
import MineOrder from './../components/MineOrder.vue'
import Circle from './../components/circle.vue'
//创建路由对象数据
const routes=[
  {
   path:'/',redirect:'/home'},
  {
   path:'/home',component:Home},
  {
   
    path:'/mine',
    component:Mine,
    children:[
      {
   path:'/mine',redirect:'/mine/msg'},
      {
   path:'order',component:MineOrder},
      {
   path:'msg',component:MineMsg}
    ]
  },
  {
   path:'/news/:id',component:News},
  {
   path:'/circle',component:Circle}
]

//创建路由
const router=createRouter(
  {
   
    history:createWebHashHistory(),
    routes
  }
)

//全局路由前置守卫
//三个参数,从哪里来,到哪里去,及next的回调函数
router.beforeEach((to,from,next)=>{
   
  console.log('从哪里来:',from)
  console.log('到哪里去:',to)
  //放行
  next()
})

//导出路由对象
export  default router

2、路由全局前置守卫设置元信息

设置路由的元信息,给页面添加title属性

//引入路由
import {
   createRouter,createWebHashHistory} from 'vue-router'
import Home from './../components/Home.vue'
import Mine from './../components/Mine.vue'
import News from './../components/News.vue'
import MineMsg from './../components/MineMsg.vue'
import MineOrder from './../components/MineOrder.vue'
import Circle from './../components/circle.vue'
//创建路由对象数据
const routes=[
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值