Skip to content

Commit 41a2cd7

Browse files
committed
Add LocationState type
1 parent ffabfc6 commit 41a2cd7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

docs/Glossary.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ A *leave hook* is a user-defined function that is called when a route is about t
4242
pathname: Pathname;
4343
search: QueryString;
4444
query: Query;
45-
state: any;
45+
state: LocationState;
4646
action: Action;
4747
key: string;
4848
};
@@ -54,6 +54,14 @@ A *location* answers two important (philosophical) questions:
5454

5555
New locations are typically created each time the URL changes. You can read more about locations in [the `history` docs](https://github.com/rackt/history/blob/master/docs/Location.md).
5656

57+
### LocationState
58+
59+
type LocationState = any;
60+
61+
A *location state* is an arbitrary object of data associated with a particular [`location`](#location). This is basically a way to tie extra state to a location that is not contained in the URL.
62+
63+
This type gets its name from the first argument to HTML5's [`pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState(\)_method) and [`replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_replaceState(\)_method) methods.
64+
5765
### Pathname
5866

5967
type Pathname = string;
@@ -64,7 +72,7 @@ A *pathname* is the portion of a URL that describes a hierarchical path, includi
6472

6573
type QueryString = string;
6674

67-
A *query string* is the portion of the URL that trails the [pathname](#pathname), including the preceeding `?`. For example, in `http://example.com/the/path?the=query`, `?the=query` is the query string. It is synonymous with `window.location.search` in web browsers.
75+
A *query string* is the portion of the URL that follows the [pathname](#pathname), including any preceeding `?`. For example, in `http://example.com/the/path?the=query`, `?the=query` is the query string. It is synonymous with `window.location.search` in web browsers.
6876

6977
### Query
7078

@@ -80,7 +88,7 @@ The word *params* refers to an object of key/value pairs that were parsed out of
8088

8189
### RedirectFunction
8290

83-
type RedirectFunction = (pathname: Pathname, query: Query | any, state: any) => void;
91+
type RedirectFunction = (pathname: Pathname, query: ?Query, state: ?LocationState) => void;
8492

8593
A *redirect function* is used in [`onEnter` hooks](#enterhook) to trigger a transition to a new URL.
8694

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
- [Advanced Usage](AdvancedUsage.md)
77
- [Server Rendering](ServerRendering.md)
88
- [Transitions](Transitions.md)
9+
- [Glossary](Glossary.md)

0 commit comments

Comments
 (0)