Skip to content

Commit 768b266

Browse files
committed
Update glossary for some new terms
1 parent 9c40706 commit 768b266

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

docs/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Stringifies the query into the pathname, using the router's config.
185185
##### `createHref(pathname, query)`
186186
Creates a URL, using the router's config. For example, it will add `#/` in front of the `pathname` for hash history.
187187

188-
##### `isActive(pathnameOrLoc, onlyActiveOnIndex)`
188+
##### `isActive(pathnameOrLoc, indexOnly)`
189189
Returns `true` or `false` depending on if the `pathnameOrLoc` is active. Will be true for every route in the route branch matched (child route is active, therefore parent is too), unless `onlyActiveOnIndex` is specified, in which case it will only match the exact path.
190190

191191

@@ -310,7 +310,7 @@ code-splitting.
310310
##### `children`
311311
Routes can be nested, `this.props.children` will contain the element created from the child route component. Please refer to the [Route Configuration](/docs/guides/basics/RouteConfiguration.md) since this is a very critical part of the router's design.
312312

313-
##### `onEnter(nextState, replaceState, callback?)`
313+
##### `onEnter(nextState, replace, callback?)`
314314
Called when a route is about to be entered. It provides the next router state and a function to redirect to another path. `this` will be the route instance that triggered the hook.
315315

316316
If `callback` is listed as a 3rd argument, this hook will run asynchronously, and the transition will block until `callback` is called.

docs/Glossary.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ This is a glossary of common terms used in the React Router codebase and documen
55
* [Action](#action)
66
* [Component](#component)
77
* [EnterHook](#enterhook)
8+
* [Hash](#hash)
89
* [LeaveHook](#leavehook)
910
* [Location](#location)
11+
* [LocationDescriptor](#locationdescriptor)
1012
* [LocationKey](#locationkey)
1113
* [LocationState](#locationstate)
1214
* [Path](#path)
@@ -21,7 +23,6 @@ This is a glossary of common terms used in the React Router codebase and documen
2123
* [RouteHook](#routehook)
2224
* [RoutePattern](#routepattern)
2325
* [Router](#router)
24-
* [RouterListener](#routerlistener)
2526
* [RouterState](#routerstate)
2627

2728
## Action
@@ -47,15 +48,21 @@ A *component* is a React component class or a string (e.g. "div"). Basically, it
4748
## EnterHook
4849

4950
```js
50-
type EnterHook = (nextState: RouterState, replaceState: RedirectFunction, callback?: Function) => any;
51+
type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: Function) => any;
5152
```
5253

53-
An *enter hook* is a user-defined function that is called when a route is about to be rendered. It receives the next [router state](#routerstate) as its first argument. The [`replaceState` function](#redirectfunction) may be used to trigger a transition to a different URL.
54+
An *enter hook* is a user-defined function that is called when a route is about to be rendered. It receives the next [router state](#routerstate) as its first argument. The [`replace` function](#redirectfunction) may be used to trigger a transition to a different URL.
5455

5556
If an enter hook needs to execute asynchronously, it may list a 3rd `callback` argument that it must call in order to cause the transition to proceed.
5657

5758
**Caution:** Using the `callback` in an enter hook causes the transition to wait until it is called. **This can lead to a non-responsive UI if you don't call it very quickly**.
5859

60+
### Hash
61+
62+
type Hash = string;
63+
64+
A *hash* is a string that represents the hash portion of the URL. It is synonymous with `window.location.hash` in web browsers.
65+
5966
## LeaveHook
6067

6168
```js
@@ -84,6 +91,21 @@ A *location* answers two important (philosophical) questions:
8491

8592
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).
8693

94+
### LocationDescriptor
95+
96+
type LocationDescriptorObject = {
97+
pathname: Pathname;
98+
search: Search;
99+
query: Query;
100+
state: LocationState;
101+
};
102+
103+
type LocationDescriptor = LocationDescriptorObject | Path;
104+
105+
A *location descriptor* is the pushable analogue of a location. Locations tell you where you are; you create location descriptors to say where to go.
106+
107+
You can read more about location descriptors in [the `history` docs](https://github.com/rackt/history/blob/master/docs/Location.md).
108+
87109
## LocationKey
88110

89111
```js
@@ -108,7 +130,7 @@ This type gets its name from the first argument to HTML5's [`pushState`][pushSta
108130
## Path
109131
110132
```js
111-
type Path = Pathname + QueryString;
133+
type Path = Pathname + QueryString + Hash;
112134
```
113135
114136
A *path* represents a URL path.
@@ -119,15 +141,15 @@ A *path* represents a URL path.
119141
type Pathname = string;
120142
```
121143
122-
A *pathname* is the portion of a URL that describes a hierarchical path, including the preceeding `/`. For example, in `http://example.com/the/path?the=query`, `/the/path` is the pathname. It is synonymous with `window.location.pathname` in web browsers.
144+
A *pathname* is the portion of a URL that describes a hierarchical path, including the preceding `/`. For example, in `http://example.com/the/path?the=query`, `/the/path` is the pathname. It is synonymous with `window.location.pathname` in web browsers.
123145

124146
## QueryString
125147

126148
```js
127149
type QueryString = string;
128150
```
129151

130-
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.
152+
A *query string* is the portion of the URL that follows the [pathname](#pathname), including any preceding `?`. 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.
131153

132154
## Query
133155

@@ -216,29 +238,17 @@ Route patterns are relative to the pattern of the parent route unless they begin
216238
217239
```js
218240
type Router = {
219-
transitionTo: (location: Location) => void;
220-
pushState: (state: ?LocationState, pathname: Pathname | Path, query?: Query) => void;
221-
replaceState: (state: ?LocationState, pathname: Pathname | Path, query?: Query) => void;
222-
go(n: Number) => void;
223-
listen(listener: RouterListener) => Function;
224-
match(location: Location, callback: RouterListener) => void;
241+
push(location: LocationDescriptor) => void;
242+
replace(location: LocationDescriptor) => void;
243+
go(n: number) => void;
244+
goBack() => void;
245+
goForward() => void;
246+
setRouteLeaveHook(hook: RouteHook) => Function;
247+
isActive(location: LocationDescriptor, indexOnly: boolean) => void;
225248
};
226249
```
227250
228-
A *router* is a [`history`](http://rackt.github.io/history) object (akin to `window.history` in web browsers) that is used to modify and listen for changes to the URL.
229-
230-
There are two primary interfaces for computing a router's next [state](#routerstate):
231-
232-
- `history.listen` is to be used in stateful environments (such as web browsers) that need to update the UI over a period of time. This method immediately invokes its `listener` argument once and returns a function that must be called to stop listening for changes
233-
- `history.match` is a function that does not update the history's internal state. This makes it ideal for server-side environments where many requests must be handled concurrently
234-
235-
## RouterListener
236-
237-
```js
238-
type RouterListener = (error: ?Error, nextState: RouterState) => void;
239-
```
240-
241-
A *router listener* is a function that is used to listen for changes to a [router](#router)'s [state](#routerstate).
251+
A *router* object allows for procedural manipulation of the routing state.
242252
243253
## RouterState
244254

0 commit comments

Comments
 (0)