Skip to content

Fix the docs for match #2683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

* [Utilities](#utilities)
* [useRoutes](#useroutescreatehistory)
* [match](#matchlocation-cb)
* [match](#match-routes-location-options--cb)
* [createRoutes](#createroutesroutes)
* [PropTypes](#proptypes)

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


## `match(location, cb)`
## `match({ routes, location, ...options }, cb)`

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.

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.

The three arguments to the callback function you pass to `match` are:
* `error`: A Javascript `Error` object if an error occurred, `undefined` otherwise.
* `redirectLocation`: A [Location](/docs/Glossary.md#location) object if the route is a redirect, `undefined` otherwise.
* `renderProps`: The props you should pass to the routing context if the route matched, `undefined` otherwise.
- `error`: A Javascript `Error` object if an error occurred, `undefined` otherwise.
- `redirectLocation`: A [Location](/docs/Glossary.md#location) object if the route is a redirect, `undefined` otherwise.
- `renderProps`: The props you should pass to the routing context if the route matched, `undefined` otherwise.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/Glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ A *router* is a [`history`](http://rackt.github.io/history) object (akin to `win
There are two primary interfaces for computing a router's next [state](#routerstate):

- `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
- `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
- `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

## RouterListener

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/advanced/ServerRendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Server rendering is a bit different than in a client because you'll want to:

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

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

It looks something like this with an imaginary JavaScript server:
Expand Down
8 changes: 2 additions & 6 deletions modules/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const createHistory = useRoutes(useBasename(createMemoryHistory))
function match({
routes,
location,
parseQueryString,
stringifyQuery,
basename
...options
}, callback) {
invariant(
location,
Expand All @@ -29,9 +27,7 @@ function match({

const history = createHistory({
routes: createRoutes(routes),
parseQueryString,
stringifyQuery,
basename
...options
})

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