/
navigationGuards.test-d.ts
57 lines (49 loc) 路 1.17 KB
/
navigationGuards.test-d.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {
createRouter,
createWebHistory,
expectType,
isNavigationFailure,
NavigationFailure,
NavigationFailureType,
RouteLocationNormalized,
RouteLocationRaw,
} from './index'
const router = createRouter({
history: createWebHistory(),
routes: [],
})
router.beforeEach((to, from) => {
return { path: '/' }
})
router.beforeEach((to, from) => {
return '/'
})
router.beforeEach((to, from) => {
return false
})
router.beforeEach((to, from, next) => {
next(undefined)
})
// @ts-expect-error
router.beforeEach((to, from, next) => {
return Symbol('not supported')
})
// @ts-expect-error
router.beforeEach(() => {
return Symbol('not supported')
})
router.beforeEach((to, from, next) => {
// @ts-expect-error
next(Symbol('not supported'))
})
router.afterEach((to, from, failure) => {
expectType<NavigationFailure | undefined | void>(failure)
if (isNavigationFailure(failure)) {
expectType<RouteLocationNormalized>(failure.from)
expectType<RouteLocationRaw>(failure.to)
}
if (isNavigationFailure(failure, NavigationFailureType.cancelled)) {
expectType<RouteLocationNormalized>(failure.from)
expectType<RouteLocationRaw>(failure.to)
}
})