mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 20:39:17 +08:00
* [@types/next] Update Router.push() method to include UrlLike type
Allow a valid UrlLike object instead of only a string type e.g
```
Router.push({
pathname: '/pathname',
query: {
prop1: '',
prop2: '',
},
});
```
https://github.com/zeit/next.js/#with-url-object-1
* Update router.d.ts
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import * as React from 'react';
|
|
import * as url from 'url';
|
|
|
|
type UrlLike = url.UrlObject | url.Url;
|
|
|
|
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|UrlLike, as?: string|UrlLike, options?: EventChangeOptions): Promise<boolean>;
|
|
replace(url: string|UrlLike, as?: string|UrlLike, 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;
|