diff --git a/README.md b/README.md index 1b5c073a..e1849a1c 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Found uses [Redux](http://redux.js.org/) for state management and [Farce](https: ## Usage ```js -import { createBrowserRouter, HttpError, Redirect, Route } from 'found'; -import { makeRouteConfig } from 'found/lib/jsx'; +import { createBrowserRouter, HttpError, makeRouteConfig, Redirect, Route } + from 'found'; /* ... */ @@ -140,7 +140,7 @@ $ npm i -S found ### Basic usage -Define a route configuration as an array of objects, or as JSX with `` elements using the `makeRouteConfig` function from `found/lib/jsx`. +Define a route configuration as an array of objects, or as JSX with `` elements using `makeRouteConfig`. ```js const routeConfig = [ @@ -209,7 +209,7 @@ A route object under the default matching algorithm and route element resolver c - `render`: a method that returns the element for the route - `children`: an array of child route objects; if using JSX configuration components, this comes from the JSX children -A route configuration consists of an array of route objects. You can generate such an array of route objects from JSX with `` elements using the `makeRouteConfig` function from `found/lib/jsx`. +A route configuration consists of an array of route objects. You can generate such an array of route objects from JSX with `` elements using `makeRouteConfig`. #### `path` @@ -355,7 +355,7 @@ If any matched routes have unresolved asynchronous component or data dependencie #### Redirects -The `Redirect` route class sets up static redirect routes. You can also use it to create JSX `` elements for use with `makeRouteConfig` from `found/lib/jsx`. This class takes `from` and `to` properties. `from` should be a path pattern as for normal routes above. `to` can be either a path pattern or a function. If it is a path pattern, the router will populate path parameters appropriately. If it is a function, it will receive the same routing state object as `getComponent` and `getData`, as described above. +The `Redirect` route class sets up static redirect routes. You can also use it to create JSX `` elements for use with `makeRouteConfig`. This class takes `from` and `to` properties. `from` should be a path pattern as for normal routes above. `to` can be either a path pattern or a function. If it is a path pattern, the router will populate path parameters appropriately. If it is a function, it will receive the same routing state object as `getComponent` and `getData`, as described above. ```js const redirect1 = new Redirect({ @@ -855,13 +855,13 @@ The top-level `found` package exports everything available in this library. It i ```js import createBrowserRouter from 'found/lib/createBrowserRouter'; +import makeRouteConfig from 'found/lib/makeRouteConfig'; import { routerShape } from 'found/lib/PropTypes'; import Route from 'found/lib/Route'; -import makeRouteConfig from 'found/lib/jsx/makeRouteConfig'; // Instead of: -// import { createBrowserRouter, Route, routerShape } from 'found'; -// import { makeRouteConfig } from 'found/lib/jsx'; +// import { createBrowserRouter, makeRouteConfig, Route, routerShape } +// from 'found'; ``` [build-badge]: https://img.shields.io/travis/4Catalyzer/found/master.svg diff --git a/examples/basic-jsx/src/index.js b/examples/basic-jsx/src/index.js index 79a2d4ae..aa93271b 100644 --- a/examples/basic-jsx/src/index.js +++ b/examples/basic-jsx/src/index.js @@ -1,8 +1,8 @@ import createBrowserRouter from 'found/lib/createBrowserRouter'; import Link from 'found/lib/Link'; +import makeRouteConfig from 'found/lib/makeRouteConfig'; import Redirect from 'found/lib/Redirect'; import Route from 'found/lib/Route'; -import makeRouteConfig from 'found/lib/jsx/makeRouteConfig'; import PropTypes from 'prop-types'; import React from 'react'; import ReactDOM from 'react-dom'; diff --git a/examples/universal/src/routeConfig.js b/examples/universal/src/routeConfig.js index beb061b0..51c534c7 100644 --- a/examples/universal/src/routeConfig.js +++ b/examples/universal/src/routeConfig.js @@ -1,7 +1,7 @@ import Link from 'found/lib/Link'; +import makeRouteConfig from 'found/lib/makeRouteConfig'; import Redirect from 'found/lib/Redirect'; import Route from 'found/lib/Route'; -import makeRouteConfig from 'found/lib/jsx/makeRouteConfig'; import PropTypes from 'prop-types'; import React from 'react'; diff --git a/src/Route.js b/src/Route.js index eeafd468..5bc0387f 100644 --- a/src/Route.js +++ b/src/Route.js @@ -1,5 +1,7 @@ -// This class is mostly for convenience with JSX. When not using JSX, using a -// POJSO will have the same effect. +/** + * Convenience class for creating normal routes with JSX. When not using JSX, + * use a POJSO instead of this class. + */ export default class Route { constructor(props) { Object.assign(this, props); diff --git a/src/index.js b/src/index.js index 151d82d6..d9c58fcd 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,7 @@ export getRenderArgs from './getRenderArgs'; export getStoreRenderArgs from './getStoreRenderArgs'; export HttpError from './HttpError'; export Link from './Link'; +export makeRouteConfig from './makeRouteConfig'; export Matcher from './Matcher'; export { matcherShape, matchShape, routerShape } from './PropTypes'; export Redirect from './Redirect'; diff --git a/src/jsx/index.js b/src/jsx/index.js deleted file mode 100644 index e2c078fd..00000000 --- a/src/jsx/index.js +++ /dev/null @@ -1 +0,0 @@ -export makeRouteConfig from './makeRouteConfig'; diff --git a/src/jsx/makeRouteConfig.js b/src/makeRouteConfig.js similarity index 83% rename from src/jsx/makeRouteConfig.js rename to src/makeRouteConfig.js index a9988478..282c2785 100644 --- a/src/jsx/makeRouteConfig.js +++ b/src/makeRouteConfig.js @@ -1,5 +1,8 @@ import React from 'react'; +/** + * Create a route configuration from JSX configuration elements. + */ export default function makeRouteConfig(node) { return React.Children.toArray(node) .filter(React.isValidElement) diff --git a/test/jsx/index.test.js b/test/jsx/index.test.js deleted file mode 100644 index acb7f614..00000000 --- a/test/jsx/index.test.js +++ /dev/null @@ -1,7 +0,0 @@ -import * as jsx from '../../src/jsx'; - -describe('found/jsx', () => { - it('should have the correct exports', () => { - expect(jsx.makeRouteConfig).toBeDefined(); - }); -}); diff --git a/test/jsx/makeRouteConfig.test.js b/test/makeRouteConfig.test.js similarity index 92% rename from test/jsx/makeRouteConfig.test.js rename to test/makeRouteConfig.test.js index b5937348..a74ce57f 100644 --- a/test/jsx/makeRouteConfig.test.js +++ b/test/makeRouteConfig.test.js @@ -1,8 +1,8 @@ import React from 'react'; -import Redirect from '../../src/Redirect'; -import Route from '../../src/Route'; -import makeRouteConfig from '../../src/jsx/makeRouteConfig'; +import makeRouteConfig from '../src/makeRouteConfig'; +import Redirect from '../src/Redirect'; +import Route from '../src/Route'; const AppPage = () => {}; const MainPage = () => {};