|
| 1 | +interface KoComponentRouterRoute { |
| 2 | + component: string; |
| 3 | +} |
| 4 | + |
| 5 | +type CallbackResult = void | false | Promise<boolean>; |
| 6 | +type DoneCallback = (boolean) => void; |
| 7 | + |
| 8 | +type KoComponentRouterPromiseMiddleware = (ctx: KoComponentRouterContext) => CallbackResult; |
| 9 | +type KoComponentRouterCallbackMiddleware = (ctx: KoComponentRouterContext, done: DoneCallback) => void; |
| 10 | +type KoComponentRouterLifecycleMiddleware = (ctx: KoComponentRouterContext) => { |
| 11 | + beforeRender: () => CallbackResult; |
| 12 | + afterRender: () => CallbackResult; |
| 13 | + beforeDispose: () => CallbackResult; |
| 14 | + afterDispose: () => CallbackResult; |
| 15 | +}; |
| 16 | +type KoComponentRouterMiddleware = KoComponentRouterPromiseMiddleware |
| 17 | + | KoComponentRouterCallbackMiddleware |
| 18 | + | KoComponentRouterLifecycleMiddleware; |
| 19 | + |
| 20 | +interface KoComponentRouterContext { |
| 21 | + $child: KoComponentRouterContext; |
| 22 | + $parent: KoComponentRouterContext; |
| 23 | + addBeforeNavigateCallback(cb: () => CallbackResult); |
| 24 | + addBeforeNavigateCallback(cb: (done: DoneCallback) => void); |
| 25 | + canonicalPath: string; |
| 26 | + element: HTMLElement; |
| 27 | + fullPath: string; |
| 28 | + params: any; |
| 29 | + path: string; |
| 30 | + pathname: string; |
| 31 | + route: KoComponentRouterRoute; |
| 32 | + router: KoComponentRouterInstance; |
| 33 | +} |
| 34 | + |
| 35 | +interface KoComponentRouterInstance { |
| 36 | + $child: KoComponentRouterInstance; |
| 37 | + $parent: KoComponentRouterInstance; |
| 38 | + base: string; |
| 39 | + ctx: KoComponentRouterContext; |
| 40 | + isRoot: boolean; |
| 41 | + isNavigating: KnockoutObservable<boolean>; |
| 42 | + |
| 43 | + getPathFromLocation(): string; |
| 44 | + resolvePath(path): any; |
| 45 | + update(path: string, push?: boolean): Promise<boolean>; |
| 46 | +} |
| 47 | + |
| 48 | +interface KoComponentRouterRoutes { |
| 49 | + [path: string]: string |
| 50 | + | KoComponentRouterRoutes |
| 51 | + | Array<string | KoComponentRouterPromiseMiddleware | KoComponentRouterLifecycleMiddleware>; |
| 52 | +} |
| 53 | + |
| 54 | +declare module 'ko-component-router' { |
| 55 | + interface RouterStatic extends KoComponentRouterInstance { |
| 56 | + } |
| 57 | + namespace RouterStatic { |
| 58 | + export var config: { base?: string; hashbang?: boolean; }; |
| 59 | + export var middleware: KoComponentRouterMiddleware[]; |
| 60 | + export var plugins: any[]; |
| 61 | + export var routes: KoComponentRouterRoutes; |
| 62 | + export const head: KoComponentRouterInstance; |
| 63 | + export const tail: KoComponentRouterInstance; |
| 64 | + |
| 65 | + export function canonicalizePath(path: string): string; |
| 66 | + export function get(index: number): KoComponentRouterInstance; |
| 67 | + export function getPath(url: string): string; |
| 68 | + export function parseUrl(url: string): { hash: string, pathname: string, search: string }; |
| 69 | + export function sameOrigin(href: string): boolean; |
| 70 | + export function update(path: string, push?: boolean): Promise<boolean>; |
| 71 | + export function update(path: string, options: { push?: boolean; force?: boolean; with?: any }): Promise<boolean>; |
| 72 | + export function use(...middleware: KoComponentRouterMiddleware[]): void; |
| 73 | + export function usePlugin(...fns): void; |
| 74 | + } |
| 75 | + |
| 76 | + export = RouterStatic; |
| 77 | +} |
0 commit comments