Skip to content

Commit ddb8d3b

Browse files
committed
add type tests for 2.2 features
1 parent e7b375c commit ddb8d3b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

types/router.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare class VueRouter {
2828
back (): void;
2929
forward (): void;
3030
getMatchedComponents (to?: RawLocation): Component[];
31-
onReady (cb: Function);
31+
onReady (cb: Function): void;
3232
addRoutes (routes: RouteConfig[]): void;
3333
resolve (to: RawLocation, current?: Route, append?: boolean): {
3434
location: Location;
@@ -54,6 +54,8 @@ export interface RouterOptions {
5454
) => { x: number, y: number } | { selector: string } | void;
5555
}
5656

57+
type RoutePropsFunction = (route: Route) => Object;
58+
5759
export interface RouteConfig {
5860
path: string;
5961
name?: string;
@@ -64,7 +66,7 @@ export interface RouteConfig {
6466
children?: RouteConfig[];
6567
meta?: any;
6668
beforeEnter?: NavigationGuard;
67-
props?: boolean | Object | Function;
69+
props?: boolean | Object | RoutePropsFunction;
6870
}
6971

7072
export interface RouteRecord {
@@ -81,7 +83,7 @@ export interface RouteRecord {
8183
redirect: (location: RawLocation) => void,
8284
next: () => void
8385
) => any;
84-
props: boolean | Object | Function | Dictionary<boolean | Object | Function>;
86+
props: boolean | Object | RoutePropsFunction | Dictionary<boolean | Object | RoutePropsFunction>;
8587
}
8688

8789
export interface Location {

types/test/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ const Hook: ComponentOptions<Vue> = {
2727
next("/");
2828
next({ path: "/" });
2929
next();
30+
},
31+
32+
beforeRouteUpdate (to, from, next) {
33+
route.params;
34+
next("/");
35+
next({ path: "/" });
36+
next();
3037
}
3138
};
3239

@@ -72,6 +79,9 @@ const router = new VueRouter({
7279
}
7380
]},
7481
{ path: "/home", alias: "/" },
82+
{ path: "/foo", props: true },
83+
{ path: "/bar", props: { id: 123 }},
84+
{ path: "/baz", props: (route: Route) => route.params },
7585
{ path: "*", redirect: "/" }
7686
]
7787
});
@@ -124,6 +134,15 @@ router.push({
124134
});
125135
router.replace({ name: "home" });
126136

137+
router.push('/', () => {}, () => {})
138+
router.replace('/foo', () => {}, () => {});
139+
140+
router.onReady(() => {});
141+
142+
router.addRoutes([
143+
{ path: '/more' }
144+
]);
145+
127146
router.go(-1);
128147
router.back();
129148
router.forward();

0 commit comments

Comments
 (0)