|
1 | | -import Vue, { ComponentOptions, PluginFunction, AsyncComponent } from "vue"; |
| 1 | +import Vue, { ComponentOptions, PluginFunction, AsyncComponent } from 'vue' |
2 | 2 |
|
3 | | -type Component = ComponentOptions<Vue> | typeof Vue | AsyncComponent; |
4 | | -type Dictionary<T> = { [key: string]: T }; |
5 | | -type ErrorHandler = (err: Error) => void; |
| 3 | +type Component = ComponentOptions<Vue> | typeof Vue | AsyncComponent |
| 4 | +type Dictionary < T > = { [key: string]: T } |
| 5 | +type ErrorHandler = (err: Error) => void |
6 | 6 |
|
7 | | -export type RouterMode = "hash" | "history" | "abstract"; |
8 | | -export type RawLocation = string | Location; |
9 | | -export type RedirectOption = RawLocation | ((to: Route) => RawLocation); |
10 | | -export type NavigationGuard<V extends Vue = Vue> = ( |
| 7 | +export type RouterMode = 'hash' | 'history' | 'abstract' |
| 8 | +export type RawLocation = string | Location |
| 9 | +export type RedirectOption = RawLocation | ((to: Route) => RawLocation) |
| 10 | +export type NavigationGuard < V extends Vue = Vue > = ( |
11 | 11 | to: Route, |
12 | 12 | from: Route, |
13 | 13 | next: (to?: RawLocation | false | ((vm: V) => any) | void) => void |
14 | 14 | ) => any |
15 | 15 |
|
16 | 16 | export declare class VueRouter { |
17 | | - constructor (options?: RouterOptions); |
| 17 | + constructor(options?: RouterOptions) |
18 | 18 |
|
19 | | - app: Vue; |
20 | | - mode: RouterMode; |
21 | | - currentRoute: Route; |
| 19 | + app: Vue |
| 20 | + mode: RouterMode |
| 21 | + currentRoute: Route |
22 | 22 |
|
23 | | - beforeEach (guard: NavigationGuard): Function; |
24 | | - beforeResolve (guard: NavigationGuard): Function; |
25 | | - afterEach (hook: (to: Route, from: Route) => any): Function; |
26 | | - push (location: RawLocation): Promise<Route>; |
27 | | - replace (location: RawLocation): Promise<Route>; |
28 | | - push (location: RawLocation, onComplete?: Function, onAbort?: ErrorHandler): void; |
29 | | - replace (location: RawLocation, onComplete?: Function, onAbort?: ErrorHandler): void; |
30 | | - go (n: number): void; |
31 | | - back (): void; |
32 | | - forward (): void; |
33 | | - getMatchedComponents (to?: RawLocation | Route): Component[]; |
34 | | - onReady (cb: Function, errorCb?: ErrorHandler): void; |
35 | | - onError (cb: ErrorHandler): void; |
36 | | - addRoutes (routes: RouteConfig[]): void; |
37 | | - resolve (to: RawLocation, current?: Route, append?: boolean): { |
38 | | - location: Location; |
39 | | - route: Route; |
40 | | - href: string; |
| 23 | + beforeEach(guard: NavigationGuard): Function |
| 24 | + beforeResolve(guard: NavigationGuard): Function |
| 25 | + afterEach(hook: (to: Route, from: Route) => any): Function |
| 26 | + push(location: RawLocation): Promise<Route> |
| 27 | + replace(location: RawLocation): Promise<Route> |
| 28 | + push( |
| 29 | + location: RawLocation, |
| 30 | + onComplete?: Function, |
| 31 | + onAbort?: ErrorHandler |
| 32 | + ): void |
| 33 | + replace( |
| 34 | + location: RawLocation, |
| 35 | + onComplete?: Function, |
| 36 | + onAbort?: ErrorHandler |
| 37 | + ): void |
| 38 | + go(n: number): void |
| 39 | + back(): void |
| 40 | + forward(): void |
| 41 | + getMatchedComponents(to?: RawLocation | Route): Component[] |
| 42 | + onReady(cb: Function, errorCb?: ErrorHandler): void |
| 43 | + onError(cb: ErrorHandler): void |
| 44 | + addRoutes(routes: RouteConfig[]): void |
| 45 | + resolve( |
| 46 | + to: RawLocation, |
| 47 | + current?: Route, |
| 48 | + append?: boolean |
| 49 | + ): { |
| 50 | + location: Location |
| 51 | + route: Route |
| 52 | + href: string |
41 | 53 | // backwards compat |
42 | | - normalizedTo: Location; |
43 | | - resolved: Route; |
44 | | - }; |
| 54 | + normalizedTo: Location |
| 55 | + resolved: Route |
| 56 | + } |
45 | 57 |
|
46 | | - static install: PluginFunction<never>; |
| 58 | + static install: PluginFunction<never> |
47 | 59 | } |
48 | 60 |
|
49 | | -type Position = { x: number, y: number }; |
50 | | -type PositionResult = Position | { selector: string, offset?: Position } | void; |
| 61 | +type Position = { x: number; y: number } |
| 62 | +type PositionResult = Position | { selector: string; offset?: Position } | void |
51 | 63 |
|
52 | 64 | export interface RouterOptions { |
53 | | - routes?: RouteConfig[]; |
54 | | - mode?: RouterMode; |
55 | | - fallback?: boolean; |
56 | | - base?: string; |
57 | | - linkActiveClass?: string; |
58 | | - linkExactActiveClass?: string; |
59 | | - parseQuery?: (query: string) => Object; |
60 | | - stringifyQuery?: (query: Object) => string; |
| 65 | + routes?: RouteConfig[] |
| 66 | + mode?: RouterMode |
| 67 | + fallback?: boolean |
| 68 | + base?: string |
| 69 | + linkActiveClass?: string |
| 70 | + linkExactActiveClass?: string |
| 71 | + parseQuery?: (query: string) => Object |
| 72 | + stringifyQuery?: (query: Object) => string |
61 | 73 | scrollBehavior?: ( |
62 | 74 | to: Route, |
63 | 75 | from: Route, |
64 | 76 | savedPosition: Position | void |
65 | | - ) => PositionResult | Promise<PositionResult>; |
| 77 | + ) => PositionResult | Promise<PositionResult> |
66 | 78 | } |
67 | 79 |
|
68 | | -type RoutePropsFunction = (route: Route) => Object; |
| 80 | +type RoutePropsFunction = (route: Route) => Object |
69 | 81 |
|
70 | 82 | export interface PathToRegexpOptions { |
71 | | - sensitive?: boolean; |
72 | | - strict?: boolean; |
73 | | - end?: boolean; |
| 83 | + sensitive?: boolean |
| 84 | + strict?: boolean |
| 85 | + end?: boolean |
74 | 86 | } |
75 | 87 |
|
76 | 88 | export interface RouteConfig { |
77 | | - path: string; |
78 | | - name?: string; |
79 | | - component?: Component; |
80 | | - components?: Dictionary<Component>; |
81 | | - redirect?: RedirectOption; |
82 | | - alias?: string | string[]; |
83 | | - children?: RouteConfig[]; |
84 | | - meta?: any; |
85 | | - beforeEnter?: NavigationGuard; |
86 | | - props?: boolean | Object | RoutePropsFunction; |
87 | | - caseSensitive?: boolean; |
88 | | - pathToRegexpOptions?: PathToRegexpOptions; |
| 89 | + path: string |
| 90 | + name?: string |
| 91 | + component?: Component |
| 92 | + components?: Dictionary<Component> |
| 93 | + redirect?: RedirectOption |
| 94 | + alias?: string | string[] |
| 95 | + children?: RouteConfig[] |
| 96 | + meta?: any |
| 97 | + beforeEnter?: NavigationGuard |
| 98 | + props?: boolean | Object | RoutePropsFunction |
| 99 | + caseSensitive?: boolean |
| 100 | + pathToRegexpOptions?: PathToRegexpOptions |
89 | 101 | } |
90 | 102 |
|
91 | 103 | export interface RouteRecord { |
92 | | - path: string; |
93 | | - regex: RegExp; |
94 | | - components: Dictionary<Component>; |
95 | | - instances: Dictionary<Vue>; |
96 | | - name?: string; |
97 | | - parent?: RouteRecord; |
98 | | - redirect?: RedirectOption; |
99 | | - matchAs?: string; |
100 | | - meta: any; |
| 104 | + path: string |
| 105 | + regex: RegExp |
| 106 | + components: Dictionary<Component> |
| 107 | + instances: Dictionary<Vue> |
| 108 | + name?: string |
| 109 | + parent?: RouteRecord |
| 110 | + redirect?: RedirectOption |
| 111 | + matchAs?: string |
| 112 | + meta: any |
101 | 113 | beforeEnter?: ( |
102 | 114 | route: Route, |
103 | 115 | redirect: (location: RawLocation) => void, |
104 | 116 | next: () => void |
105 | | - ) => any; |
106 | | - props: boolean | Object | RoutePropsFunction | Dictionary<boolean | Object | RoutePropsFunction>; |
| 117 | + ) => any |
| 118 | + props: |
| 119 | + | boolean |
| 120 | + | Object |
| 121 | + | RoutePropsFunction |
| 122 | + | Dictionary<boolean | Object | RoutePropsFunction> |
107 | 123 | } |
108 | 124 |
|
109 | 125 | export interface Location { |
110 | | - name?: string; |
111 | | - path?: string; |
112 | | - hash?: string; |
113 | | - query?: Dictionary<string | (string | null)[] | null | undefined>; |
114 | | - params?: Dictionary<string>; |
115 | | - append?: boolean; |
116 | | - replace?: boolean; |
| 126 | + name?: string |
| 127 | + path?: string |
| 128 | + hash?: string |
| 129 | + query?: Dictionary<string | (string | null)[] | null | undefined> |
| 130 | + params?: Dictionary<string> |
| 131 | + append?: boolean |
| 132 | + replace?: boolean |
117 | 133 | } |
118 | 134 |
|
119 | 135 | export interface Route { |
120 | | - path: string; |
121 | | - name?: string; |
122 | | - hash: string; |
123 | | - query: Dictionary<string | (string | null)[]>; |
124 | | - params: Dictionary<string>; |
125 | | - fullPath: string; |
126 | | - matched: RouteRecord[]; |
127 | | - redirectedFrom?: string; |
128 | | - meta?: any; |
| 136 | + path: string |
| 137 | + name?: string |
| 138 | + hash: string |
| 139 | + query: Dictionary<string | (string | null)[]> |
| 140 | + params: Dictionary<string> |
| 141 | + fullPath: string |
| 142 | + matched: RouteRecord[] |
| 143 | + redirectedFrom?: string |
| 144 | + meta?: any |
129 | 145 | } |
0 commit comments