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
-**Feature/Deprecation:** Call `getChildRoutes` and `getIndexRoute` with `partialNextState`; deprecate accessing `location` directly in favor of `partialNextState.location` there ([#3556], [#3561], [#3569], [Upgrade Guide](/upgrade-guides/v2.5.0.md#getchildroutes-getindexroute-signature))
Copy file name to clipboardExpand all lines: docs/API.md
+35-21Lines changed: 35 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,15 +70,8 @@ function createElement(Component, props) {
70
70
}
71
71
```
72
72
73
-
##### `stringifyQuery(queryObject)`
74
-
A function used to convert an object from [`<Link>`](#link)s or calls to
75
-
[`transitionTo`](#transitiontopathname-query-state) to a URL query string.
76
-
77
-
##### `parseQueryString(queryString)`
78
-
A function used to convert a query string into an object that gets passed to route component props.
79
-
80
73
##### `onError(error)`
81
-
While the router is matching, errors may bubble up, here is your opportunity to catch and deal with them. Typically these will come from async features like [`route.getComponents`](#getcomponentsnextstate-callback), [`route.getIndexRoute`](#getindexroutelocation-callback), and [`route.getChildRoutes`](#getchildrouteslocation-callback).
74
+
While the router is matching, errors may bubble up, here is your opportunity to catch and deal with them. Typically these will come from async features like [`route.getComponents`](#getcomponentsnextstate-callback), [`route.getIndexRoute`](#getindexroutepartialnextstate-callback), and [`route.getChildRoutes`](#getchildroutespartialnextstate-callback).
82
75
83
76
##### `onUpdate()`
84
77
Called whenever the router updates its state in response to URL changes.
@@ -88,6 +81,10 @@ This is primarily for integrating with other libraries that need to participate
88
81
89
82
Ensure that you render a `<RouterContext>` at the end of the line, passing all the props passed to `render`.
Please see the [`examples/`](/examples) directory of the repository for extensive examples of using `<Router>`.
@@ -101,7 +98,7 @@ A `<Link>` can know when the route it links to is active and automatically apply
101
98
102
99
#### Props
103
100
##### `to`
104
-
A [location descriptor](https://github.com/mjackson/history/blob/master/docs/Glossary.md#locationdescriptor). Usually this is a string or an object, with the following semantics:
101
+
A [location descriptor](https://github.com/ReactJSTraining/history/blob/master/docs/Glossary.md#locationdescriptor). Usually this is a string or an object, with the following semantics:
105
102
106
103
* If it's a string it represents the absolute path to link to, e.g. `/users/123` (relative paths are not supported).
107
104
* If it's an object it can have four keys:
@@ -110,7 +107,7 @@ A [location descriptor](https://github.com/mjackson/history/blob/master/docs/Glo
110
107
*`hash`: A hash to put in the URL, e.g. `#a-hash`.
111
108
*`state`: State to persist to the `location`.
112
109
113
-
_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to the hash.
110
+
_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to `hash`._
114
111
115
112
##### `activeClassName`
116
113
The className a `<Link>` receives when its route is active. No active class by default.
@@ -127,6 +124,12 @@ If `true`, the `<Link>` will only be active when the current route exactly match
127
124
##### *others*
128
125
You can also pass props you'd like to be on the `<a>` such as a `title`, `id`, `className`, etc.
129
126
127
+
##### `query`**([deprecated](/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)**
128
+
129
+
##### `hash`**([deprecated](/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)**
130
+
131
+
##### `state`**([deprecated](/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)**
132
+
130
133
#### Example
131
134
Given a route like `<Route path="/users/:userId" />`:
132
135
@@ -185,6 +188,18 @@ Go back one entry in the history.
185
188
##### `goForward()`
186
189
Go forward one entry in the history.
187
190
191
+
##### `setRouteLeaveHook(route, hook)`
192
+
Registers the given hook function to run before leaving the given route.
193
+
194
+
During a normal transition, the hook function receives the next location as its only argument and can return either a prompt message (string) to show the user, to make sure they want to leave the page; or `false`, to prevent the transition. Any other return value will have no effect.
195
+
196
+
During the beforeunload event (in browsers) the hook receives no arguments.
197
+
In this case it must return a prompt message to prevent the transition.
198
+
199
+
Returns a function that may be used to unbind the listener.
200
+
201
+
You don't need to manually tear down the route leave hook in most cases. We automatically remove all attached route leave hooks after leaving the associated route.
202
+
188
203
##### `createPath(pathOrLoc, query)`
189
204
Stringifies the query into the pathname, using the router's config.
190
205
@@ -289,8 +304,7 @@ class Users extends React.Component {
289
304
```
290
305
291
306
##### `getComponent(nextState, callback)`
292
-
Same as `component` but asynchronous, useful for
293
-
code-splitting.
307
+
Same as `component` but asynchronous, useful for code-splitting.
294
308
295
309
###### `callback` signature
296
310
`cb(err, component)`
@@ -340,8 +354,8 @@ A plain JavaScript object route definition. `<Router>` turns JSX `<Route>`s into
340
354
##### `childRoutes`
341
355
An array of child routes, same as `children` in JSX route configs.
342
356
343
-
##### `getChildRoutes(location, callback)`
344
-
Same as `childRoutes` but asynchronous and receives the `location`. Useful for code-splitting and dynamic route matching (given some state or session data to return a different set of child routes).
Same as `childRoutes` but asynchronous and receives `partialNextState`. Useful for code-splitting and dynamic route matching (given some state or session data to return a different set of child routes).
345
359
346
360
###### `callback` signature
347
361
`cb(err, routesArray)`
@@ -371,8 +385,8 @@ let myRoute = {
371
385
372
386
let myRoute = {
373
387
path:'picture/:id',
374
-
getChildRoutes(location, cb) {
375
-
let { state } =location
388
+
getChildRoutes(partialNextState, cb) {
389
+
let { state } =partialNextState
376
390
377
391
if (state &&state.fromDashboard) {
378
392
cb(null, [dashboardPictureRoute])
@@ -386,9 +400,9 @@ let myRoute = {
386
400
##### `indexRoute`
387
401
The [index route](/docs/guides/IndexRoutes.md). This is the same as specifying an `<IndexRoute>` child when using JSX route configs.
388
402
389
-
##### `getIndexRoute(location, callback)`
403
+
##### `getIndexRoute(partialNextState, callback)`
390
404
391
-
Same as `indexRoute`, but asynchronous and receives the `location`. As with `getChildRoutes`, this can be useful for code-splitting and dynamic route matching.
405
+
Same as `indexRoute`, but asynchronous and receives `partialNextState`. As with `getChildRoutes`, this can be useful for code-splitting and dynamic route matching.
392
406
393
407
###### `callback` signature
394
408
`cb(err, route)`
@@ -407,7 +421,7 @@ let myRoute = {
407
421
// async index route
408
422
let myRoute = {
409
423
path:'courses',
410
-
getIndexRoute(location, cb) {
424
+
getIndexRoute(partialNextState, cb) {
411
425
// do something async here
412
426
cb(null, myIndexRoute)
413
427
}
@@ -587,9 +601,9 @@ For more details, please see the [histories guide](/docs/guides/Histories.md).
587
601
`useRouterHistory` is a `history` enhancer that configures a given `createHistory` factory to work with React Router. This allows using custom histories in addition to the bundled singleton histories.
Copy file name to clipboardExpand all lines: docs/guides/DynamicRouting.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,15 @@ A router is the perfect place to handle code splitting: it's responsible for set
10
10
11
11
React Router does all of its [path matching](/docs/guides/RouteMatching.md) and component fetching asynchronously, which allows you to not only load up the components lazily, *but also lazily load the route configuration*. You really only need one route definition in your initial bundle, the router can resolve the rest on demand.
12
12
13
-
Routes may define [`getChildRoutes`](/docs/API.md#getchildrouteslocation-callback), [`getIndexRoute`](/docs/API.md#getindexroutelocation-callback), and [`getComponents`](/docs/API.md#getcomponentsnextstate-callback) methods. These are asynchronous and only called when needed. We call it "gradual matching". React Router will gradually match the URL and fetch only the amount of route configuration and components it needs to match the URL and render.
13
+
Routes may define [`getChildRoutes`](/docs/API.md#getchildroutespartialnextstate-callback), [`getIndexRoute`](/docs/API.md#getindexroutepartialnextstate-callback), and [`getComponents`](/docs/API.md#getcomponentsnextstate-callback) methods. These are asynchronous and only called when needed. We call it "gradual matching". React Router will gradually match the URL and fetch only the amount of route configuration and components it needs to match the URL and render.
14
14
15
15
Coupled with a smart code splitting tool like [webpack](http://webpack.github.io/), a once tiresome architecture is now simple and declarative.
Copy file name to clipboardExpand all lines: docs/guides/Histories.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,11 +139,11 @@ render(
139
139
140
140
If you'd like to further customize the history options or use other
141
141
enhancers from
142
-
[history](https://github.com/mjackson/history/) you can use
142
+
[history](https://github.com/ReactJSTraining/history/) you can use
143
143
`useRouterHistory`.
144
144
145
145
Be aware that `useRouterHistory` already pre-enhances your history
146
-
factory with the [useQueries](https://github.com/mjackson/history/blob/master/docs/QuerySupport.md) and [useBasename](https://github.com/mjackson/history/blob/master/docs/BasenameSupport.md) enhancers from `history`.
146
+
factory with the [useQueries](https://github.com/ReactJSTraining/history/blob/master/docs/QuerySupport.md) and [useBasename](https://github.com/ReactJSTraining/history/blob/master/docs/BasenameSupport.md) enhancers from `history`.
0 commit comments