diff --git a/docs/API.md b/docs/API.md index 2451e543a7..42e9e2feab 100644 --- a/docs/API.md +++ b/docs/API.md @@ -24,7 +24,7 @@ * [Utilities](#utilities) * [useRoutes](#useroutescreatehistory) - * [match](#matchlocation-cb) + * [match](#match-routes-location-options--cb) * [createRoutes](#createroutesroutes) * [PropTypes](#proptypes) @@ -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. diff --git a/docs/Glossary.md b/docs/Glossary.md index b6db0bf629..aa7072e0ae 100644 --- a/docs/Glossary.md +++ b/docs/Glossary.md @@ -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 diff --git a/docs/guides/advanced/ServerRendering.md b/docs/guides/advanced/ServerRendering.md index 02b923bed4..e898fd5d91 100644 --- a/docs/guides/advanced/ServerRendering.md +++ b/docs/guides/advanced/ServerRendering.md @@ -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 [``](/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: diff --git a/modules/match.js b/modules/match.js index bb8fe6be0d..e7ca4cdedc 100644 --- a/modules/match.js +++ b/modules/match.js @@ -18,9 +18,7 @@ const createHistory = useRoutes(useBasename(createMemoryHistory)) function match({ routes, location, - parseQueryString, - stringifyQuery, - basename + ...options }, callback) { invariant( location, @@ -29,9 +27,7 @@ function match({ const history = createHistory({ routes: createRoutes(routes), - parseQueryString, - stringifyQuery, - basename + ...options }) // Allow match({ location: '/the/path', ... })