重定向和别名
重定向-->redirect
字符串形式配置,访问
/
重定向到/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对象形式配置
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函数模式(可以传参)
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
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