Last active
June 8, 2017 09:54
-
-
Save axross/8b6a4739e3f0b1e4636ea884131b0f00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Params = {}; | |
type ContextBase<R, C> = { | |
router: Router<R, C>; | |
route: Route<R, C>; | |
next: () => Promise<R>; | |
url: string; | |
baseUrl: string; | |
path: string; | |
params: Params; | |
keys: any[]; // https://github.com/pillarjs/path-to-regexp | |
}; | |
type ActualContext<R, C> = ContextBase<R, C> & C; | |
export type Route<R, C> = { | |
path: string; | |
name?: string; | |
parent?: Route<R, C> | null; | |
children?: Route<R, C>[] | null; | |
action?: (context: ActualContext<R, C>, params: Params) => R | Promise<R>; | |
}; | |
type RouterOptions<R, C> = { | |
context?: C, | |
baseUrl?: string, | |
resolveRoute: (context: ActualContext<R, C>, params: Params) => any; | |
}; | |
declare class Router<R, C = {}> { | |
constructor(routes: Route<R, C> | Route<R, C>[], options?: RouterOptions<R, C>); | |
resolve(path: string): Promise<R>; | |
resolve(path: ActualContext<R, C>): Promise<R>; | |
} | |
export default Router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment