Skip to content

Commit 12f72e0

Browse files
committed
Merge pull request #2683 from taion/match-docs
Fix the docs for match
2 parents 1760d7c + 7d50e24 commit 12f72e0

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

docs/API.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
* [Utilities](#utilities)
2626
* [useRoutes](#useroutescreatehistory)
27-
* [match](#matchlocation-cb)
27+
* [match](#match-routes-location-options--cb)
2828
* [createRoutes](#createroutesroutes)
2929
* [PropTypes](#proptypes)
3030

@@ -677,14 +677,16 @@ Returns a new `createHistory` function that may be used to create history object
677677
- isActive(pathname, query, indexOnly=false)
678678

679679

680-
## `match(location, cb)`
680+
## `match({ routes, location, ...options }, cb)`
681681

682682
This function is to be used for server-side rendering. It matches a set of routes to a location, without rendering, and calls a `callback(error, redirectLocation, renderProps)` when it's done.
683683

684+
The additional `options` are used to create the history. You can specify `basename` to control the base name for URLs, as well as the pair of `parseQueryString` and `stringifyQuery` to control query string parsing and serializing.
685+
684686
The three arguments to the callback function you pass to `match` are:
685-
* `error`: A Javascript `Error` object if an error occurred, `undefined` otherwise.
686-
* `redirectLocation`: A [Location](/docs/Glossary.md#location) object if the route is a redirect, `undefined` otherwise.
687-
* `renderProps`: The props you should pass to the routing context if the route matched, `undefined` otherwise.
687+
- `error`: A Javascript `Error` object if an error occurred, `undefined` otherwise.
688+
- `redirectLocation`: A [Location](/docs/Glossary.md#location) object if the route is a redirect, `undefined` otherwise.
689+
- `renderProps`: The props you should pass to the routing context if the route matched, `undefined` otherwise.
688690

689691
If all three parameters are `undefined`, this means that there was no route found matching the given location.
690692

docs/Glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ A *router* is a [`history`](http://rackt.github.io/history) object (akin to `win
230230
There are two primary interfaces for computing a router's next [state](#routerstate):
231231

232232
- `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 pure asynchronous 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
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
234234

235235
## RouterListener
236236

docs/guides/advanced/ServerRendering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Server rendering is a bit different than in a client because you'll want to:
88

99
To facilitate these needs, you drop one level lower than the [`<Router>`](/docs/API.md#Router) API with:
1010

11-
- [`match`](https://github.com/rackt/react-router/blob/master/docs/API.md#matchlocation-cb) to match the routes to a location without rendering
11+
- [`match`](/docs/API.md#match-routes-location-options--cb) to match the routes to a location without rendering
1212
- `RouterContext` for synchronous rendering of route components
1313

1414
It looks something like this with an imaginary JavaScript server:

modules/match.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ const createHistory = useRoutes(useBasename(createMemoryHistory))
1818
function match({
1919
routes,
2020
location,
21-
parseQueryString,
22-
stringifyQuery,
23-
basename
21+
...options
2422
}, callback) {
2523
invariant(
2624
location,
@@ -29,9 +27,7 @@ function match({
2927

3028
const history = createHistory({
3129
routes: createRoutes(routes),
32-
parseQueryString,
33-
stringifyQuery,
34-
basename
30+
...options
3531
})
3632

3733
// Allow match({ location: '/the/path', ... })

0 commit comments

Comments
 (0)