You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
All development happens [on GitHub](https://github.com/ReactTraining/history). When [creating a pull request](https://help.github.com/articles/creating-a-pull-request/), please make sure that all of the following apply:
1
+
All development happens [on GitHub](https://github.com/remix-run/history). When [creating a pull request](https://help.github.com/articles/creating-a-pull-request/), please make sure that all of the following apply:
2
2
3
3
- If you're adding a new feature or "fixing" a bug, please go into detail about your use case and why you think you need that feature or that bug fixed. This library has lots and lots of dependents, and we can't afford to make changes lightly without understanding why.
4
4
- The tests pass. The test suite will automatically run when you create the PR. All you need to do is wait a few minutes to see the result in the PR.
The history library lets you easily manage session history anywhere JavaScript runs. A `history` object abstracts away the differences in various environments and provides a minimal API that lets you manage the history stack, navigate, and persist state between sessions.
9
7
10
8
## Documentation
11
9
12
10
Documentation for version 5 can be found in the [docs](docs) directory. This is the current stable release. Version 5 is used in React Router version 6.
13
11
14
-
Documentation for version 4 can be found [on the v4 branch](https://github.com/ReactTraining/history/tree/v4/docs). Version 4 is used in React Router versions 4 and 5.
12
+
Documentation for version 4 can be found [on the v4 branch](https://github.com/remix-run/history/tree/v4/docs). Version 4 is used in React Router versions 4 and 5.
15
13
16
14
## Changes
17
15
18
-
To see the changes that were made in a given release, please lookup the tag on [the releases page](https://github.com/ReactTraining/history/releases).
16
+
To see the changes that were made in a given release, please lookup the tag on [the releases page](https://github.com/remix-run/history/releases).
19
17
20
-
For changes released in version 4.6.3 and earlier, please see [the `CHANGES.md` file](https://github.com/ReactTraining/history/blob/845d690c5576c7f55ecbe14babe0092e8e5bc2bb/CHANGES.md).
18
+
For changes released in version 4.6.3 and earlier, please see [the `CHANGES.md` file](https://github.com/remix-run/history/blob/845d690c5576c7f55ecbe14babe0092e8e5bc2bb/CHANGES.md).
21
19
22
20
## Development
23
21
24
-
Development of the current stable release, version 5, happens on [the `master` branch](https://github.com/ReactTraining/history/tree/master). Please keep in mind that this branch may include some work that has not yet been published as part of an official release. However, since `master` is always stable, you should feel free to build your own working release straight from master at any time.
22
+
Development of the current stable release, version 5, happens on [the `main` branch](https://github.com/remix-run/history/tree/main). Please keep in mind that this branch may include some work that has not yet been published as part of an official release. However, since `main` is always stable, you should feel free to build your own working release straight from `main` at any time.
25
23
26
24
If you're interested in helping out, please read [our contributing guidelines](CONTRIBUTING.md).
Copy file name to clipboardExpand all lines: docs/api-reference.md
+67-75Lines changed: 67 additions & 75 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
# history API Reference
4
4
5
-
This is the API reference for [the history JavaScript library](https://github.com/ReactTraining/history).
5
+
This is the API reference for [the history JavaScript library](https://github.com/remix-run/history).
6
6
7
7
The history library provides an API for tracking application history using [location](#location) objects that contain URLs and state. This reference includes type signatures and return values for the interfaces in the library. Please read the [getting started guide](getting-started.md) if you're looking for explanations about how to use the library to accomplish a specific task.
8
8
@@ -50,17 +50,17 @@ To prevent the location from changing, use [`history.block`](#history.block). Th
50
50
51
51
<aname="creating-hrefs"></a>
52
52
53
-
### Creating Hrefs
53
+
### Creating `href` values
54
54
55
55
If you're building a link, you'll want to use [`history.createHref`](#history.createhref) to get a URL you can use as the value of `<a href>`.
56
56
57
-
----------
57
+
---
58
58
59
59
<aname="reference"></a>
60
60
61
61
## Reference
62
62
63
-
The [source code](https://github.com/ReactTraining/history/tree/master/packages/history) for the history library is written in TypeScript, but it is compiled to JavaScript before publishing. Some of the function signatures in this reference include their TypeScript type annotations, but you can always refer to the original source as well.
63
+
The [source code](https://github.com/remix-run/history/tree/main/packages/history) for the history library is written in TypeScript, but it is compiled to JavaScript before publishing. Some of the function signatures in this reference include their TypeScript type annotations, but you can always refer to the original source as well.
64
64
65
65
<aname="action"></a>
66
66
@@ -77,27 +77,41 @@ See [the Getting Started guide](getting-started.md) for more information.
77
77
<aname="createbrowserhistory"></a>
78
78
<aname="browserhistory"></a>
79
79
80
-
### `createBrowserHistory`
80
+
### `History`
81
+
82
+
A `History` object represents the shared interface for `BrowserHistory`, `HashHistory`, and `MemoryHistory`.
function createBrowserHistory(options?: { window?:Window }):BrowserHistory;
111
+
112
+
interfaceBrowserHistoryextendsHistory {}
113
+
```
114
+
101
115
</details>
102
116
103
117
A browser history object keeps track of the browsing history of an application using the browser's built-in history stack. It is designed to run in modern web browsers that support the HTML5 history interface including `pushState`, `replaceState`, and the `popstate` event.
@@ -121,15 +135,16 @@ See [the Getting Started guide](getting-started.md) for more information.
A hash history object keeps track of the browsing history of an application using the browser's built-in history stack. It is designed to be run in modern web browsers that support the HTML5 history interface including `pushState`, `replaceState`, and the `popstate` event.
@@ -187,27 +192,18 @@ See [the Getting Started guide](getting-started.md) for more information.
187
192
<summary>Type declaration</summary>
188
193
189
194
```ts
190
-
declarecreateMemoryHistory({
195
+
function createMemoryHistory({
191
196
initialEntries?: InitialEntry[],
192
197
initialIndex?: number
193
198
}):MemoryHistory;
194
199
195
-
typeInitialEntry=string|PartialLocation;
200
+
typeInitialEntry=string|Partial<Location>;
196
201
197
-
interfaceMemoryHistory<SextendsState=State> {
202
+
interfaceMemoryHistoryextendsHistory {
198
203
readonly index:number;
199
-
readonly action:Action;
200
-
readonly location:Location<S>;
201
-
createHref(to:To):string;
202
-
push(to:To, state?:S):void;
203
-
replace(to:To, state?:S):void;
204
-
go(n:number):void;
205
-
back():void;
206
-
forward():void;
207
-
listen(listener:Listener<S>): () =>void;
208
-
block(blocker:Blocker<S>): () =>void;
209
204
}
210
205
```
206
+
211
207
</details>
212
208
213
209
A memory history object keeps track of the browsing history of an application using an internal array. This makes it ideal in situations where you need complete control over the history stack, like React Native and tests.
@@ -249,16 +245,17 @@ See [the Navigation guide](navigation.md) for more information.
249
245
<summary>Type declaration</summary>
250
246
251
247
```ts
252
-
interfaceBlocker<SextendsState=State> {
253
-
(tx:Transition<S>):void;
248
+
interfaceBlocker {
249
+
(tx:Transition):void;
254
250
}
255
251
256
-
interfaceTransition<SextendsState=State> {
252
+
interfaceTransition {
257
253
action:Action;
258
-
location:Location<S>;
254
+
location:Location;
259
255
retry():void;
260
256
}
261
257
```
258
+
262
259
</details>
263
260
264
261
Prevents changes to the history stack from happening. This is useful when you want to prevent the user navigating away from the current page, for example when they have some unsaved data on the current page.
@@ -316,15 +313,16 @@ The current index in the history stack.
316
313
<summary>Type declaration</summary>
317
314
318
315
```ts
319
-
interfaceListener<SextendsState=State> {
320
-
(update:Update<S>):void;
316
+
interfaceListener {
317
+
(update:Update):void;
321
318
}
322
319
323
-
interfaceUpdate<SextendsState=State> {
320
+
interfaceUpdate {
324
321
action:Action;
325
-
location:Location<S>;
322
+
location:Location;
326
323
}
327
324
```
325
+
328
326
</details>
329
327
330
328
Starts listening for location changes and calls the given callback with an `Update` when it does.
@@ -351,15 +349,15 @@ Also see [`history.listen`](#history.listen).
351
349
352
350
<aname="history.push"></a>
353
351
354
-
### `history.push(to: To, state?: State)`
352
+
### `history.push(to: To, state?: any)`
355
353
356
354
Pushes a new entry onto the stack.
357
355
358
356
See [the Navigation guide](navigation.md) for more information.
359
357
360
358
<aname="history.replace"></a>
361
359
362
-
### `history.replace(to: To, state?: State)`
360
+
### `history.replace(to: To, state?: any)`
363
361
364
362
Replaces the current entry in the stack with a new one.
365
363
@@ -373,14 +371,15 @@ See [the Navigation guide](navigation.md) for more information.
373
371
<summary>Type declaration</summary>
374
372
375
373
```ts
376
-
interfaceLocation<SextendsState=State> {
374
+
interfaceLocation {
377
375
pathname:string;
378
376
search:string;
379
377
hash:string;
380
-
state:S;
378
+
state:unknown;
381
379
key:string;
382
380
}
383
381
```
382
+
384
383
</details>
385
384
386
385
A `location` is a particular entry in the history stack, usually analogous to a "page" or "screen" in your app. As the user clicks on links and moves around the app, the current location changes.
@@ -433,15 +432,7 @@ This can be useful in situations where you need to keep track of 2 different sta
433
432
434
433
### State
435
434
436
-
<details>
437
-
<summary>Type declaration</summary>
438
-
439
-
```ts
440
-
typeState=object|null;
441
-
```
442
-
</details>
443
-
444
-
A [`State`](https://github.com/ReactTraining/history/blob/0f992736/packages/history/index.ts#L61) value is an object of extra information that is associated with a [`Location`](#location) but that does not appear in the URL. This value is always associated with that location.
435
+
A `State` value is an arbitrary value that holds extra information associated with a [`Location`](#location) but does not appear in the URL. This value is always associated with that location.
445
436
446
437
See [the Navigation guide](navigation.md) for more information.
447
438
@@ -453,16 +444,17 @@ See [the Navigation guide](navigation.md) for more information.
453
444
<summary>Type declaration</summary>
454
445
455
446
```ts
456
-
typeTo=string|PartialPath;
447
+
typeTo=string|Partial<Path>;
457
448
458
-
interfacePartialPath {
459
-
pathname?:string;
460
-
search?:string;
461
-
hash?:string;
449
+
interfacePath {
450
+
pathname:string;
451
+
search:string;
452
+
hash:string;
462
453
}
463
454
```
455
+
464
456
</details>
465
457
466
-
A [`To`](https://github.com/ReactTraining/history/blob/0f992736/packages/history/index.ts#L212) value represents a destination location, but doesn't contain all the information that a normal [`location`](#location) object does. It is primarily used as the first argument to [`history.push`](#history.push) and [`history.replace`](#history.replace).
458
+
A [`To`](https://github.com/remix-run/history/blob/main/packages/history/index.ts#L178) value represents a destination location, but doesn't contain all the information that a normal [`location`](#location) object does. It is primarily used as the first argument to [`history.push`](#history.push) and [`history.replace`](#history.replace).
467
459
468
-
See [the Navigation guide](navigation.md) for more information.
460
+
See [the Navigation guide](navigation.md) for more information.
0 commit comments