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