Files
DefinitelyTyped/types/next/router.d.ts
2017-09-26 11:15:49 -07:00

37 lines
1.1 KiB
TypeScript

import * as React from 'react';
export interface EventChangeOptions {
shallow?: boolean;
[key: string]: any;
}
export type RouterCallback = () => void;
export interface SingletonRouter {
readyCallbacks: RouterCallback[];
ready(cb: RouterCallback): void;
// router properties
readonly components: { [key: string]: { Component: React.ComponentType<any>, err: any } };
readonly pathname: string;
readonly route: string;
readonly asPath?: string;
readonly query?: { [key: string]: any };
// router methods
reload(route: string): Promise<void>;
back(): void;
push(url: string, as?: string, options?: EventChangeOptions): Promise<boolean>;
replace(url: string, as?: string, options?: EventChangeOptions): Promise<boolean>;
prefetch(url: string): Promise<React.ComponentType<any>>;
// router events
onAppUpdated?(nextRoute: string): void;
onRouteChangeStart?(url: string): void;
onBeforeHistoryChange?(as: string): void;
onRouteChangeComplete?(url: string): void;
onRouteChangeError?(error: any, url: string): void;
}
export const Singleton: SingletonRouter;
export default Singleton;