1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export as namespace History;
|
7 |
|
8 | export type Action = 'PUSH' | 'POP' | 'REPLACE';
|
9 | export type UnregisterCallback = () => void;
|
10 |
|
11 | export interface History<HistoryLocationState = LocationState> {
|
12 | length: number;
|
13 | action: Action;
|
14 | location: Location<HistoryLocationState>;
|
15 | push(path: Path, state?: HistoryLocationState): void;
|
16 | push(location: LocationDescriptor<HistoryLocationState>): void;
|
17 | replace(path: Path, state?: HistoryLocationState): void;
|
18 | replace(location: LocationDescriptor<HistoryLocationState>): void;
|
19 | go(n: number): void;
|
20 | goBack(): void;
|
21 | goForward(): void;
|
22 | block(prompt?: boolean | string | TransitionPromptHook<HistoryLocationState>): UnregisterCallback;
|
23 | listen(listener: LocationListener<HistoryLocationState>): UnregisterCallback;
|
24 | createHref(location: LocationDescriptorObject<HistoryLocationState>): Href;
|
25 | }
|
26 |
|
27 | export interface Location<S = LocationState> {
|
28 | pathname: Pathname;
|
29 | search: Search;
|
30 | state: S;
|
31 | hash: Hash;
|
32 | key?: LocationKey;
|
33 | }
|
34 |
|
35 | export interface LocationDescriptorObject<S = LocationState> {
|
36 | pathname?: Pathname;
|
37 | search?: Search;
|
38 | state?: S;
|
39 | hash?: Hash;
|
40 | key?: LocationKey;
|
41 | }
|
42 |
|
43 | export namespace History {
|
44 | export type LocationDescriptor<S = LocationState> = Path | LocationDescriptorObject<S>;
|
45 | export type LocationKey = string;
|
46 | export type LocationListener<S = LocationState> = (location: Location<S>, action: Action) => void;
|
47 |
|
48 | export type LocationState = unknown;
|
49 | export type Path = string;
|
50 | export type Pathname = string;
|
51 | export type Search = string;
|
52 | export type TransitionHook<S = LocationState> = (location: Location<S>, callback: (result: any) => void) => any;
|
53 | export type TransitionPromptHook<S = LocationState> = (
|
54 | location: Location<S>,
|
55 | action: Action,
|
56 | ) => string | false | void;
|
57 | export type Hash = string;
|
58 | export type Href = string;
|
59 | }
|
60 |
|
61 | export type LocationDescriptor<S = LocationState> = History.LocationDescriptor<S>;
|
62 | export type LocationKey = History.LocationKey;
|
63 | export type LocationListener<S = LocationState> = History.LocationListener<S>;
|
64 | export type LocationState = History.LocationState;
|
65 | export type Path = History.Path;
|
66 | export type Pathname = History.Pathname;
|
67 | export type Search = History.Search;
|
68 | export type TransitionHook<S = LocationState> = History.TransitionHook<S>;
|
69 | export type TransitionPromptHook<S = LocationState> = History.TransitionPromptHook<S>;
|
70 | export type Hash = History.Hash;
|
71 | export type Href = History.Href;
|
72 |
|
73 | import { default as createBrowserHistory } from './createBrowserHistory';
|
74 | import { default as createHashHistory } from './createHashHistory';
|
75 | import { default as createMemoryHistory } from './createMemoryHistory';
|
76 | import { createLocation, locationsAreEqual } from './LocationUtils';
|
77 | import { parsePath, createPath } from './PathUtils';
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | export interface Module {
|
83 | createBrowserHistory: typeof createBrowserHistory;
|
84 | createHashHistory: typeof createHashHistory;
|
85 | createMemoryHistory: typeof createMemoryHistory;
|
86 | createLocation: typeof createLocation;
|
87 | locationsAreEqual: typeof locationsAreEqual;
|
88 | parsePath: typeof parsePath;
|
89 | createPath: typeof createPath;
|
90 | }
|
91 |
|
92 | export * from './createBrowserHistory';
|
93 | export * from './createHashHistory';
|
94 | export * from './createMemoryHistory';
|
95 | export { createLocation, locationsAreEqual } from './LocationUtils';
|
96 | export { parsePath, createPath } from './PathUtils';
|
97 | export { createBrowserHistory, createHashHistory, createMemoryHistory };
|