Blog
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)

HiuZing

🍑
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)
  • 前端面试题

  • JavaScript

  • Vue2

  • port

  • CSS

  • Node.js

  • JavaScript优化

  • uniapp

  • Mini Program

  • TypeScript

  • 面向对象编程

  • UI组件

  • Plugin

  • Vue3

    • 教程

    • Vue Router

      • API

      • 基础

        • 入门
        • 路由模式
        • 命名路由
        • 历史记录
        • 路由传参
        • 嵌套路由
        • 命名视图
        • 重定向和别名
      • 进阶

      • 实例

    • API

    • Vuex

    • 实例处理方案

    • 文档

    • 用法

  • 性能优化

  • Axios

  • 状态管理

  • React

  • Mock

  • Icon

  • Template

  • 构建工具

  • 项目规范配置

  • Taro

  • SVG

  • React Native

  • 前端
  • Vue3
  • Vue Router
  • 基础
HiuZing
2023-03-28

重定向和别名

重定向-->redirect

  1. 字符串形式配置,访问/ 重定向到/user (地址栏显示/,内容为/user路由的内容)

    const routes: Array<RouteRecordRaw> = [
        {
            path:'/',
            component:()=> import('../components/root.vue'),
            redirect:'/user1',
            children:[
                {
                    path:'/user1',
                    components:{
                        default:()=> import('../components/A.vue')
                    }
                },
                {
                    path:'/user2',
                    components:{
                        bbb:()=> import('../components/B.vue'),
                        ccc:()=> import('../components/C.vue')
                    }
                }
            ]
        }
    ]
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
  2. 对象形式配置

    const routes: Array<RouteRecordRaw> = [
        {
            path: '/',
            component: () => import('../components/root.vue'),
            redirect: { path: '/user1' },
            children: [
                {
                    path: '/user1',
                    components: {
                        default: () => import('../components/A.vue')
                    }
                },
                {
                    path: '/user2',
                    components: {
                        bbb: () => import('../components/B.vue'),
                        ccc: () => import('../components/C.vue')
                    }
                }
            ]
        }
    ]
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
  3. 函数模式(可以传参)

    const routes: Array<RouteRecordRaw> = [
        {
            path: '/',
            component: () => import('../components/root.vue'),
            redirect: (to) => {
                return {
                    path: '/user1',
                    query: to.query
                }
            },
            children: [
                {
                    path: '/user1',
                    components: {
                        default: () => import('../components/A.vue')
                    }
                },
                {
                    path: '/user2',
                    components: {
                        bbb: () => import('../components/B.vue'),
                        ccc: () => import('../components/C.vue')
                    }
                }
            ]
        }
    ]
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27

# 别名 alias

将 / 别名为/root,意味着当用户访问 /root时,URL 仍然是 /user,但会被匹配为用户正在访问 /

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        component: () => import('../components/root.vue'),
        alias:["/root","/root2","/root3"],
        children: [
            {
                path: 'user1',
                components: {
                    default: () => import('../components/A.vue')
                }
            },
            {
                path: 'user2',
                components: {
                    bbb: () => import('../components/B.vue'),
                    ccc: () => import('../components/C.vue')
                }
            }
        ]
    }
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
上次更新: 2024/08/14, 04:14:33
命名视图
导航守卫

← 命名视图 导航守卫→

最近更新
01
React Native 使用SVG
08-13
02
Docker基础命令
08-04
03
算数逻辑单元
07-30
更多文章>
Theme by Vdoing | Copyright © 2021-2024 WeiXiaojing | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式