• vue-router 路由


    一、组件

            1、 切换路由

               to="/user"  切换路由的地址

                 存放路由

    1. <router-view>router-view>
    2. <router-link to="/">首页router-link>

            2、路由配置  /router/index

    1. //普通
    2. {
    3. path:"/user",
    4. name:"user",
    5. component:()=>import(xxx)
    6. }
    7. //传参
    8. {
    9. path:"/product/:id",
    10. name:"product",
    11. component:()=>import(xxx)
    12. }
    13. "/product/abc">
    14. //在页面中获取 $route.params.id
    15. //404
    16. //要配置在最后面
    17. {
    18. path:“*”,
    19. }

            3、编程式路由 跳转$router

                前进  forward()  go(1)

                后退  back()       go(-1)

                切换路由  push("/about")

                替换路由(不留当前页面历史记录)  replace("/about")

            4、路由信息$route

                路由参数 params

                查询 query

                地址 path

                名称 name

                哈希值 hash

                全地址 fullPath

            5、路由守卫

               1.组件内部

                    进入前 beforeRouterEnter(to,from,next)

    1. //to要进入的路由
    2. //from 从哪个页面进入
    3. //next 下一步
    4. //next() 进入to页面
    5. //next(true) 进入to页面
    6. //next(false) 不跳转
    7. //next("/login") 跳转到登录页面

                    离开前 beforeRouterLeave

                    更新前 beforeRouterUpdate

                2.全局

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

                    afterEnter

                3.独享

                    beforeRnter()  作用:进入离开页面前做拦截,处理事情(跳转提示,权限检查)

            6、路由元信息

    1. {
    2. path:path,name,component,
    3. meta:{
    4. noFooter:true
    5. }
    6. }
    7. //$route.meta.noFooter 范围

            7、路由查询参数

                传递 next("/login?redirect=/cart")

                获取 var redirect=this.$route

  • 相关阅读:
    【HTML5入门指北】第一篇 初始HTML5
    docke入门基础知识
    深度学习之SuperViT
    PMP提分练习
    【523能源】伍二三能源科技招募--高薪销售精英(年薪超百万)
    7-51 愿天下有情人都是失散多年的兄妹——dfs
    Redis入门(基础篇)笔记
    Spring MVC组件之ViewResolver
    再看tomcat的体会
    Vscode配置C/C++编程环境@配置C和CPP的运行和调试环境@配置过程的相关问题@中文文件名乱码@build和debug方案组合配置
  • 原文地址:https://blog.csdn.net/fagdg/article/details/126189116