Skip to content

Commit

Permalink
Document and expose matchStemRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Aug 1, 2018
1 parent c14c489 commit b060181
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,30 @@ The options object also accepts a number of optional properties:
- `historyMiddlewares`: an array of Farce history middlewares; by default, an array containing only `queryMiddleware`
- `historyOptions`: additional configuration options for the Farce history store enhancer
- `matcherOptions`: configuration options for the route matcher
- `matchStemRoutes`: whether to match routes that are not leaf routes (see below); defaults to `true` if not explicitly specified, though future releases may deprecate and warn on this behavior in advance of changing the default
- `renderPending`: a custom render function called when some routes are not yet ready to render, due to those routes have unresolved asynchronous dependencies and no route-level `render` method for handling the loading state
- `renderReady`: a custom render function called when all routes are ready to render
- `renderError`: a custom render function called if an `HttpError` is thrown while resolving route elements
- `render`: a custom render function called in all cases, superseding `renderPending`, `renderReady`, and `renderError`; by default, this is `createRender({ renderPending, renderReady, renderError })`
`matchStemRoutes` in `matcherOptions` controls whether routes that are not leaf routes will match. Given the following route configuration:
```js
<Route path="foo">
<Route path="bar" />
</Route>
```
The path `/foo` will match if `matchStemRoutes` is enabled. To match on `/foo` when `matchStemRoutes` is disabled, specify this equivalent route configuration:
```js
<Route path="foo">
<Route />
<Route path="bar" />
</Route>
```
The `renderPending`, `renderReady`, `renderError`, and `render` functions receive the routing state object as an argument, with the following additional properties:
- `elements`: if present, an array the resolved elements for the matched routes; the array item will be `null` for routes without elements
Expand Down Expand Up @@ -689,7 +708,7 @@ const store = createStore(
middlewares: [queryMiddleware],
}),
createMatchEnhancer(
new Matcher(routeConfig),
new Matcher(routeConfig, { matchStemRoutes: false }),
),
),
);
Expand Down
2 changes: 2 additions & 0 deletions src/createFarceRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function createFarceRouter({
historyMiddlewares,
historyOptions,
routeConfig,
matcherOptions,
...options
}) {
const ConnectedRouter = createConnectedRouter(options);
Expand All @@ -26,6 +27,7 @@ export default function createFarceRouter({
historyMiddlewares,
historyOptions,
routeConfig,
matcherOptions,
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/createFarceStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function createFarceStore({
historyMiddlewares,
historyOptions,
routeConfig,
matcherOptions,
}) {
const store = createStore(
combineReducers({
Expand All @@ -23,7 +24,7 @@ export default function createFarceStore({
protocol: historyProtocol,
middlewares: historyMiddlewares || [queryMiddleware],
}),
createMatchEnhancer(new Matcher(routeConfig)),
createMatchEnhancer(new Matcher(routeConfig, matcherOptions)),
),
);

Expand Down

0 comments on commit b060181

Please sign in to comment.