diff --git a/.watchmanconfig b/.watchmanconfig
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/packages/react-router-config/modules/__tests__/integration-test.js b/packages/react-router-config/modules/__tests__/integration-test.js
index 369de78986..84db0c28c0 100644
--- a/packages/react-router-config/modules/__tests__/integration-test.js
+++ b/packages/react-router-config/modules/__tests__/integration-test.js
@@ -1,26 +1,28 @@
-import React from 'react'
-import ReactDOMServer from 'react-dom/server'
-import StaticRouter from 'react-router/StaticRouter'
-import matchRoutes from '../matchRoutes'
-import renderRoutes from '../renderRoutes'
+import React from "react";
+import ReactDOMServer from "react-dom/server";
+import StaticRouter from "react-router/StaticRouter";
+import matchRoutes from "../matchRoutes";
+import renderRoutes from "../renderRoutes";
-describe('integration', () => {
- it('generates the same matches in renderRoutes and matchRoutes', () => {
- const rendered = []
+describe("integration", () => {
+ it("generates the same matches in renderRoutes and matchRoutes", () => {
+ const rendered = [];
const Comp = ({ match, route: { routes } }) => (
- rendered.push(match),
- renderRoutes(routes)
- )
+ rendered.push(match), renderRoutes(routes)
+ );
const routes = [
- { path: '/pepper',
+ {
+ path: "/pepper",
component: Comp,
routes: [
- { path: '/pepper/:type',
+ {
+ path: "/pepper/:type",
component: Comp,
routes: [
- { path: '/pepper/:type/scoville',
+ {
+ path: "/pepper/:type/scoville",
component: Comp
}
]
@@ -28,47 +30,49 @@ describe('integration', () => {
]
},
- { path: undefined,
+ {
+ path: undefined,
component: Comp,
routes: [
- { path: '/ghost',
+ {
+ path: "/ghost",
component: Comp
}
]
}
- ]
+ ];
- const pathname = '/pepper/jalepeno'
- const branch = matchRoutes(routes, pathname)
+ const pathname = "/pepper/jalepeno";
+ const branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
{renderRoutes(routes)}
- )
- expect(branch.length).toEqual(2)
- expect(rendered.length).toEqual(2)
- expect(branch[0].match).toEqual(rendered[0])
- expect(branch[1].match).toEqual(rendered[1])
- })
+ );
+ expect(branch.length).toEqual(2);
+ expect(rendered.length).toEqual(2);
+ expect(branch[0].match).toEqual(rendered[0]);
+ expect(branch[1].match).toEqual(rendered[1]);
+ });
-
-
- it('generates the same matches in renderRoutes and matchRoutes with pathless routes', () => {
- const rendered = []
+ it("generates the same matches in renderRoutes and matchRoutes with pathless routes", () => {
+ const rendered = [];
const Comp = ({ match, route: { routes } }) => (
- rendered.push(match),
- renderRoutes(routes)
- )
+ rendered.push(match), renderRoutes(routes)
+ );
const routes = [
- { path: '/pepper',
+ {
+ path: "/pepper",
component: Comp,
routes: [
- { path: '/pepper/:type',
+ {
+ path: "/pepper/:type",
component: Comp,
routes: [
- { path: '/pepper/:type/scoville',
+ {
+ path: "/pepper/:type/scoville",
component: Comp
}
]
@@ -76,115 +80,111 @@ describe('integration', () => {
]
},
- { path: undefined,
+ {
+ path: undefined,
component: Comp,
routes: [
- { path: '/ghost',
+ {
+ path: "/ghost",
component: Comp
}
]
}
- ]
+ ];
- const pathname = '/ghost'
- const branch = matchRoutes(routes, pathname)
+ const pathname = "/ghost";
+ const branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
{renderRoutes(routes)}
- )
- expect(branch.length).toEqual(2)
- expect(rendered.length).toEqual(2)
- expect(branch[0].match).toEqual(rendered[0])
- expect(branch[1].match).toEqual(rendered[1])
- })
-
+ );
+ expect(branch.length).toEqual(2);
+ expect(rendered.length).toEqual(2);
+ expect(branch[0].match).toEqual(rendered[0]);
+ expect(branch[1].match).toEqual(rendered[1]);
+ });
-
- it('generates the same matches in renderRoutes and matchRoutes with routes using exact', () => {
- const rendered = []
+ it("generates the same matches in renderRoutes and matchRoutes with routes using exact", () => {
+ const rendered = [];
const Comp = ({ match, route: { routes } }) => (
- rendered.push(match),
- renderRoutes(routes)
- )
+ rendered.push(match), renderRoutes(routes)
+ );
const routes = [
// should skip
{
- path: '/pepper/habanero',
+ path: "/pepper/habanero",
component: Comp,
exact: true
},
// should match
{
- path: '/pepper',
+ path: "/pepper",
component: Comp,
exact: true
}
- ]
+ ];
- const pathname = '/pepper'
- const branch = matchRoutes(routes, pathname)
+ const pathname = "/pepper";
+ const branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
{renderRoutes(routes)}
- )
- expect(branch.length).toEqual(1)
- expect(rendered.length).toEqual(1)
- expect(branch[0].match).toEqual(rendered[0])
- })
-
-
+ );
+ expect(branch.length).toEqual(1);
+ expect(rendered.length).toEqual(1);
+ expect(branch[0].match).toEqual(rendered[0]);
+ });
- it('generates the same matches in renderRoutes and matchRoutes with routes using exact + strict', () => {
- const rendered = []
+ it("generates the same matches in renderRoutes and matchRoutes with routes using exact + strict", () => {
+ const rendered = [];
const Comp = ({ match, route: { routes } }) => (
- rendered.push(match),
- renderRoutes(routes)
- )
+ rendered.push(match), renderRoutes(routes)
+ );
const routes = [
// should match
{
- path: '/pepper/',
+ path: "/pepper/",
component: Comp,
strict: true,
exact: true,
routes: [
// should skip
{
- path: '/pepper',
+ path: "/pepper",
component: Comp,
strict: true,
exact: true
}
]
}
- ]
+ ];
- let pathname = '/pepper'
- let branch = matchRoutes(routes, pathname)
+ let pathname = "/pepper";
+ let branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
{renderRoutes(routes)}
- )
- expect(branch.length).toEqual(0)
- expect(rendered.length).toEqual(0)
+ );
+ expect(branch.length).toEqual(0);
+ expect(rendered.length).toEqual(0);
- pathname = '/pepper/'
- branch = matchRoutes(routes, pathname)
+ pathname = "/pepper/";
+ branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
{renderRoutes(routes)}
- )
+ );
- expect(branch.length).toEqual(1)
- expect(rendered.length).toEqual(1)
- expect(branch[0].match).toEqual(rendered[0])
- })
-})
+ expect(branch.length).toEqual(1);
+ expect(rendered.length).toEqual(1);
+ expect(branch[0].match).toEqual(rendered[0]);
+ });
+});
diff --git a/packages/react-router-config/modules/__tests__/matchRoutes-test.js b/packages/react-router-config/modules/__tests__/matchRoutes-test.js
index 7ce9b0f7b3..185da5c027 100644
--- a/packages/react-router-config/modules/__tests__/matchRoutes-test.js
+++ b/packages/react-router-config/modules/__tests__/matchRoutes-test.js
@@ -1,96 +1,90 @@
-import matchRoutes from '../matchRoutes'
+import matchRoutes from "../matchRoutes";
-it('finds matched routes', () => {
+it("finds matched routes", () => {
const routes = [
- { path: '/',
+ {
+ path: "/",
exact: true
},
- { path: '/pepper',
+ {
+ path: "/pepper",
routes: [
- { path: '/pepper/:type',
- routes: [
- { path: '/pepper/:type/scoville' }
- ]
+ {
+ path: "/pepper/:type",
+ routes: [{ path: "/pepper/:type/scoville" }]
}
]
},
- { path: undefined,
- routes: [
- { path: '/ghost' }
- ]
+ {
+ path: undefined,
+ routes: [{ path: "/ghost" }]
}
- ]
-
- const branch = matchRoutes(routes, '/pepper/jalepeno')
- expect(branch.length).toEqual(2)
- expect(branch[0].route).toEqual(routes[1])
- expect(branch[1].route).toEqual(routes[1].routes[0])
-})
-
-it('stops matching after finding the first match, just like ', () => {
- const routes = [
- { path: '/static' },
- { path: '/:dynamic' }
- ]
- const branch = matchRoutes(routes, '/static')
- expect(branch.length).toEqual(1)
- expect(branch[0].route).toEqual(routes[0])
-})
+ ];
+ const branch = matchRoutes(routes, "/pepper/jalepeno");
+ expect(branch.length).toEqual(2);
+ expect(branch[0].route).toEqual(routes[1]);
+ expect(branch[1].route).toEqual(routes[1].routes[0]);
+});
-describe('pathless routes', () => {
+it("stops matching after finding the first match, just like ", () => {
+ const routes = [{ path: "/static" }, { path: "/:dynamic" }];
+ const branch = matchRoutes(routes, "/static");
+ expect(branch.length).toEqual(1);
+ expect(branch[0].route).toEqual(routes[0]);
+});
+describe("pathless routes", () => {
const routes = [
- { path: '/',
+ {
+ path: "/",
routes: [
- { path: undefined,
- routes: [
- { path: '/habenero' }
- ]
+ {
+ path: undefined,
+ routes: [{ path: "/habenero" }]
}
]
}
- ]
+ ];
- it('matches child paths', () => {
- const branch = matchRoutes(routes, '/habenero')
- expect(branch.length).toEqual(3)
- expect(branch[0].route).toEqual(routes[0])
- expect(branch[1].route).toEqual(routes[0].routes[0])
- expect(branch[2].route).toEqual(routes[0].routes[0].routes[0])
- })
+ it("matches child paths", () => {
+ const branch = matchRoutes(routes, "/habenero");
+ expect(branch.length).toEqual(3);
+ expect(branch[0].route).toEqual(routes[0]);
+ expect(branch[1].route).toEqual(routes[0].routes[0]);
+ expect(branch[2].route).toEqual(routes[0].routes[0].routes[0]);
+ });
- it('returns the parent match', () => {
- const branch = matchRoutes(routes, '/habenero')
- expect(branch.length).toBe(3)
- expect(branch[1].match).toBe(branch[0].match)
- })
+ it("returns the parent match", () => {
+ const branch = matchRoutes(routes, "/habenero");
+ expect(branch.length).toBe(3);
+ expect(branch[1].match).toBe(branch[0].match);
+ });
- describe('at the root', () => {
+ describe("at the root", () => {
const routes = [
- { path: undefined,
- routes: [
- { path: '/anaheim' }
- ]
+ {
+ path: undefined,
+ routes: [{ path: "/anaheim" }]
}
- ]
+ ];
it('matches "/"', () => {
- const branch = matchRoutes(routes, '/')
- expect(branch.length).toEqual(1)
- expect(branch[0].route).toEqual(routes[0])
- })
+ const branch = matchRoutes(routes, "/");
+ expect(branch.length).toEqual(1);
+ expect(branch[0].route).toEqual(routes[0]);
+ });
- it('returns a root match for a pathless root route', () => {
- const branch = matchRoutes(routes, '/')
+ it("returns a root match for a pathless root route", () => {
+ const branch = matchRoutes(routes, "/");
expect(branch[0].match).toEqual({
- path: '/',
- url: '/',
+ path: "/",
+ url: "/",
params: {},
isExact: true
- })
- })
- })
-})
+ });
+ });
+ });
+});
diff --git a/packages/react-router-config/modules/__tests__/renderRoutes-test.js b/packages/react-router-config/modules/__tests__/renderRoutes-test.js
index 7f98d623ba..9045225c43 100644
--- a/packages/react-router-config/modules/__tests__/renderRoutes-test.js
+++ b/packages/react-router-config/modules/__tests__/renderRoutes-test.js
@@ -1,394 +1,436 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import ReactDOMServer from 'react-dom/server'
-import StaticRouter from 'react-router/StaticRouter'
-import Router from 'react-router/Router'
-import renderRoutes from '../renderRoutes'
-import createHistory from 'history/createMemoryHistory'
-
-describe('renderRoutes', () => {
- let renderedRoutes
- let renderedExtraProps
+import React from "react";
+import ReactDOM from "react-dom";
+import ReactDOMServer from "react-dom/server";
+import StaticRouter from "react-router/StaticRouter";
+import Router from "react-router/Router";
+import renderRoutes from "../renderRoutes";
+import createHistory from "history/createMemoryHistory";
+
+describe("renderRoutes", () => {
+ let renderedRoutes;
+ let renderedExtraProps;
const Comp = ({ route, route: { routes }, ...extraProps }) => (
renderedRoutes.push(route),
renderedExtraProps.push(extraProps),
renderRoutes(routes)
- )
+ );
beforeEach(() => {
- renderedRoutes = []
- renderedExtraProps = []
- })
+ renderedRoutes = [];
+ renderedExtraProps = [];
+ });
- it('renders pathless routes', () => {
+ it("renders pathless routes", () => {
const routeToMatch = {
component: Comp
- }
- const routes = [routeToMatch]
+ };
+ const routes = [routeToMatch];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(1)
- expect(renderedRoutes[0]).toEqual(routeToMatch)
- })
+ );
+ expect(renderedRoutes.length).toEqual(1);
+ expect(renderedRoutes[0]).toEqual(routeToMatch);
+ });
- it('passes extraProps to the component rendered by a pathless route', () => {
+ it("passes extraProps to the component rendered by a pathless route", () => {
const routeToMatch = {
component: Comp
- }
- const routes = [routeToMatch]
- const extraProps = { anExtraProp: 'anExtraPropValue' }
+ };
+ const routes = [routeToMatch];
+ const extraProps = { anExtraProp: "anExtraPropValue" };
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes, extraProps)}
- )
- expect(renderedExtraProps.length).toEqual(1)
- expect(renderedExtraProps[0].anExtraProp).toEqual('anExtraPropValue')
- })
+ );
+ expect(renderedExtraProps.length).toEqual(1);
+ expect(renderedExtraProps[0].anExtraProp).toEqual("anExtraPropValue");
+ });
- it('passes extraProps to the component rendered by a matched route', () => {
+ it("passes extraProps to the component rendered by a matched route", () => {
const routeToMatch = {
component: Comp,
- path: '/'
- }
- const routes = [routeToMatch, {
- component: Comp
- }]
- const extraProps = { anExtraProp: 'anExtraPropValue' }
+ path: "/"
+ };
+ const routes = [
+ routeToMatch,
+ {
+ component: Comp
+ }
+ ];
+ const extraProps = { anExtraProp: "anExtraPropValue" };
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes, extraProps)}
- )
- expect(renderedExtraProps.length).toEqual(1)
- expect(renderedExtraProps[0].anExtraProp).toEqual('anExtraPropValue')
- })
+ );
+ expect(renderedExtraProps.length).toEqual(1);
+ expect(renderedExtraProps[0].anExtraProp).toEqual("anExtraPropValue");
+ });
- describe('Switch usage', () => {
- it('renders the first matched route', () => {
+ describe("Switch usage", () => {
+ it("renders the first matched route", () => {
const routeToMatch = {
component: Comp,
- path: '/'
- }
- const routes = [routeToMatch, {
- component: Comp
- }]
+ path: "/"
+ };
+ const routes = [
+ routeToMatch,
+ {
+ component: Comp
+ }
+ ];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(1)
- expect(renderedRoutes[0]).toEqual(routeToMatch)
- })
+ );
+ expect(renderedRoutes.length).toEqual(1);
+ expect(renderedRoutes[0]).toEqual(routeToMatch);
+ });
- it('renders the first matched route in nested routes', () => {
+ it("renders the first matched route in nested routes", () => {
const childRouteToMatch = {
component: Comp,
- path: '/'
- }
+ path: "/"
+ };
const routeToMatch = {
component: Comp,
- path: '/',
- routes: [childRouteToMatch, {
+ path: "/",
+ routes: [
+ childRouteToMatch,
+ {
+ component: Comp
+ }
+ ]
+ };
+ const routes = [
+ routeToMatch,
+ {
component: Comp
- }]
- }
- const routes = [routeToMatch, {
- component: Comp
- }]
+ }
+ ];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(2)
- expect(renderedRoutes[0]).toEqual(routeToMatch)
- expect(renderedRoutes[1]).toEqual(childRouteToMatch)
- })
+ );
+ expect(renderedRoutes.length).toEqual(2);
+ expect(renderedRoutes[0]).toEqual(routeToMatch);
+ expect(renderedRoutes[1]).toEqual(childRouteToMatch);
+ });
- it('does not remount a ', () => {
- const node = document.createElement('div')
+ it("does not remount a ", () => {
+ const node = document.createElement("div");
- let mountCount = 0
+ let mountCount = 0;
- const App = ({ route: { routes } }) => (
- renderRoutes(routes)
- )
+ const App = ({ route: { routes } }) => renderRoutes(routes);
class Comp extends React.Component {
componentDidMount() {
- mountCount++
+ mountCount++;
}
render() {
- return
+ return ;
}
}
const routes = [
- { path: '/',
+ {
+ path: "/",
component: App,
routes: [
- { path: '/one',
+ {
+ path: "/one",
component: Comp,
- key: 'comp'
+ key: "comp"
},
- { path: '/two',
+ {
+ path: "/two",
component: Comp,
- key: 'comp'
+ key: "comp"
},
- { path: '/three',
- component: Comp,
+ {
+ path: "/three",
+ component: Comp
}
]
}
- ]
+ ];
const history = createHistory({
- initialEntries: [ '/one' ]
- })
+ initialEntries: ["/one"]
+ });
- ReactDOM.render((
-
- {renderRoutes(routes)}
-
- ), node)
+ ReactDOM.render(
+ {renderRoutes(routes)},
+ node
+ );
- expect(mountCount).toBe(1)
+ expect(mountCount).toBe(1);
- history.push('/one')
- expect(mountCount).toBe(1)
+ history.push("/one");
+ expect(mountCount).toBe(1);
- history.push('/two')
- expect(mountCount).toBe(1)
+ history.push("/two");
+ expect(mountCount).toBe(1);
- history.push('/three')
- expect(mountCount).toBe(2)
- })
+ history.push("/three");
+ expect(mountCount).toBe(2);
+ });
- it('passes props to Switch', () => {
- const App = ({ route: { routes } }) => (
- renderRoutes(routes)
- )
+ it("passes props to Switch", () => {
+ const App = ({ route: { routes } }) => renderRoutes(routes);
const routeToMatch = {
component: Comp,
- path: '/one'
- }
+ path: "/one"
+ };
const routes = [
- { path: '/',
+ {
+ path: "/",
component: App,
routes: [
- { path: '/one',
+ {
+ path: "/one",
component: Comp
}
]
}
- ]
+ ];
ReactDOMServer.renderToString(
-
- {renderRoutes(routes, {}, {location: { pathname: '/one' }})}
+
+ {renderRoutes(routes, {}, { location: { pathname: "/one" } })}
- )
+ );
- expect(renderedRoutes.length).toEqual(1)
- expect(renderedRoutes[0]).toEqual(routeToMatch)
- })
- })
+ expect(renderedRoutes.length).toEqual(1);
+ expect(renderedRoutes[0]).toEqual(routeToMatch);
+ });
+ });
- describe('routes with exact', () => {
- it('renders the exact route', () => {
+ describe("routes with exact", () => {
+ it("renders the exact route", () => {
const routeToMatch = {
component: Comp,
- path: '/path/child',
+ path: "/path/child",
exact: true,
- routes: [{
- component: Comp
- }]
- }
- const routes = [{
- component: Comp,
- path: '/path',
- exact: true
- }, routeToMatch]
+ routes: [
+ {
+ component: Comp
+ }
+ ]
+ };
+ const routes = [
+ {
+ component: Comp,
+ path: "/path",
+ exact: true
+ },
+ routeToMatch
+ ];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(2)
- expect(renderedRoutes[0]).toEqual(routeToMatch)
- expect(renderedRoutes[1]).toEqual({ component: Comp })
- })
-
- it('skips exact route and does not render it and any of its child routes', () => {
- const routes = [{
- component: Comp,
- path: '/path',
- exact: true,
- routes: [{
- component: Comp
- }, {
- component: Comp
- }]
- }]
+ );
+ expect(renderedRoutes.length).toEqual(2);
+ expect(renderedRoutes[0]).toEqual(routeToMatch);
+ expect(renderedRoutes[1]).toEqual({ component: Comp });
+ });
+
+ it("skips exact route and does not render it and any of its child routes", () => {
+ const routes = [
+ {
+ component: Comp,
+ path: "/path",
+ exact: true,
+ routes: [
+ {
+ component: Comp
+ },
+ {
+ component: Comp
+ }
+ ]
+ }
+ ];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
+ );
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(0)
- })
+ );
+ expect(renderedRoutes.length).toEqual(0);
+ });
- it('renders the matched exact route but not its child routes if they do not match', () => {
- const routes = [{
- // should render
- component: Comp,
- path: '/path',
- exact: true,
- routes: [{
- // should skip
- component: Comp,
- path: '/path/child',
- exact: true
- }, {
+ it("renders the matched exact route but not its child routes if they do not match", () => {
+ const routes = [
+ {
// should render
- component: Comp
- }]
- }]
+ component: Comp,
+ path: "/path",
+ exact: true,
+ routes: [
+ {
+ // should skip
+ component: Comp,
+ path: "/path/child",
+ exact: true
+ },
+ {
+ // should render
+ component: Comp
+ }
+ ]
+ }
+ ];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
+ );
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(2)
- expect(renderedRoutes[0]).toEqual(routes[0])
- expect(renderedRoutes[1]).toEqual(routes[0].routes[1])
- })
- })
-
- describe('routes with exact + strict', () => {
- it('renders the exact strict route', () => {
+ );
+ expect(renderedRoutes.length).toEqual(2);
+ expect(renderedRoutes[0]).toEqual(routes[0]);
+ expect(renderedRoutes[1]).toEqual(routes[0].routes[1]);
+ });
+ });
+
+ describe("routes with exact + strict", () => {
+ it("renders the exact strict route", () => {
const routeToMatch = {
component: Comp,
- path: '/path/',
- exact: true,
- strict: true
- }
- const routes = [{
- // should skip
- component: Comp,
- path: '/path',
+ path: "/path/",
exact: true,
strict: true
- // should render
- }, routeToMatch]
+ };
+ const routes = [
+ {
+ // should skip
+ component: Comp,
+ path: "/path",
+ exact: true,
+ strict: true
+ // should render
+ },
+ routeToMatch
+ ];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(1)
- expect(renderedRoutes[0]).toEqual(routeToMatch)
- })
+ );
+ expect(renderedRoutes.length).toEqual(1);
+ expect(renderedRoutes[0]).toEqual(routeToMatch);
+ });
- it('skips exact strict route and does not render it and any of its child routes', () => {
- const routes = [{
- component: Comp,
- path: '/path/',
- exact: true,
- strict: true,
- routes: [{
- component: Comp
- }, {
- component: Comp
- }]
- }]
+ it("skips exact strict route and does not render it and any of its child routes", () => {
+ const routes = [
+ {
+ component: Comp,
+ path: "/path/",
+ exact: true,
+ strict: true,
+ routes: [
+ {
+ component: Comp
+ },
+ {
+ component: Comp
+ }
+ ]
+ }
+ ];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
+ );
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
+ );
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(0)
- })
+ );
+ expect(renderedRoutes.length).toEqual(0);
+ });
- it('renders the matched exact strict route but not its child routes if they do not match', () => {
- const routes = [{
- // should skip
- component: Comp,
- path: '/path',
- exact: true,
- strict: true
- }, {
- // should render
- component: Comp,
- path: '/path/',
- exact: true,
- strict: true,
- routes: [{
+ it("renders the matched exact strict route but not its child routes if they do not match", () => {
+ const routes = [
+ {
// should skip
component: Comp,
+ path: "/path",
exact: true,
- strict: true,
- path: '/path'
- }, {
+ strict: true
+ },
+ {
// should render
component: Comp,
+ path: "/path/",
exact: true,
strict: true,
- path: '/path/'
- }]
- }]
+ routes: [
+ {
+ // should skip
+ component: Comp,
+ exact: true,
+ strict: true,
+ path: "/path"
+ },
+ {
+ // should render
+ component: Comp,
+ exact: true,
+ strict: true,
+ path: "/path/"
+ }
+ ]
+ }
+ ];
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
+ );
ReactDOMServer.renderToString(
-
+
{renderRoutes(routes)}
- )
- expect(renderedRoutes.length).toEqual(2)
- expect(renderedRoutes[0]).toEqual(routes[1])
- expect(renderedRoutes[1]).toEqual(routes[1].routes[1])
- })
- })
-})
+ );
+ expect(renderedRoutes.length).toEqual(2);
+ expect(renderedRoutes[0]).toEqual(routes[1]);
+ expect(renderedRoutes[1]).toEqual(routes[1].routes[1]);
+ });
+ });
+});
diff --git a/packages/react-router-config/modules/index.js b/packages/react-router-config/modules/index.js
index 60265064be..5b1835849d 100644
--- a/packages/react-router-config/modules/index.js
+++ b/packages/react-router-config/modules/index.js
@@ -1,2 +1,2 @@
-export matchRoutes from './matchRoutes'
-export renderRoutes from './renderRoutes'
+export matchRoutes from "./matchRoutes";
+export renderRoutes from "./renderRoutes";
diff --git a/packages/react-router-config/modules/matchRoutes.js b/packages/react-router-config/modules/matchRoutes.js
index f63b2d071e..358fc58382 100644
--- a/packages/react-router-config/modules/matchRoutes.js
+++ b/packages/react-router-config/modules/matchRoutes.js
@@ -1,29 +1,29 @@
-import matchPath from 'react-router/matchPath'
-import Router from 'react-router/Router'
+import matchPath from "react-router/matchPath";
+import Router from "react-router/Router";
// ensure we're using the exact code for default root match
-const { computeMatch } = Router.prototype
+const { computeMatch } = Router.prototype;
-const matchRoutes = (routes, pathname, /*not public API*/branch = []) => {
- routes.some((route) => {
+const matchRoutes = (routes, pathname, /*not public API*/ branch = []) => {
+ routes.some(route => {
const match = route.path
? matchPath(pathname, route)
: branch.length
? branch[branch.length - 1].match // use parent match
- : computeMatch(pathname) // use default "root" match
+ : computeMatch(pathname); // use default "root" match
if (match) {
- branch.push({ route, match })
+ branch.push({ route, match });
if (route.routes) {
- matchRoutes(route.routes, pathname, branch)
+ matchRoutes(route.routes, pathname, branch);
}
}
- return match
- })
+ return match;
+ });
- return branch
-}
+ return branch;
+};
-export default matchRoutes
+export default matchRoutes;
diff --git a/packages/react-router-config/modules/renderRoutes.js b/packages/react-router-config/modules/renderRoutes.js
index 843014410f..85286e5733 100644
--- a/packages/react-router-config/modules/renderRoutes.js
+++ b/packages/react-router-config/modules/renderRoutes.js
@@ -1,21 +1,22 @@
-import React from 'react'
-import Switch from 'react-router/Switch'
-import Route from 'react-router/Route'
+import React from "react";
+import Switch from "react-router/Switch";
+import Route from "react-router/Route";
-const renderRoutes = (routes, extraProps = {}, switchProps = {}) => routes ? (
-
- {routes.map((route, i) => (
- (
-
- )}
- />
- ))}
-
-) : null
+const renderRoutes = (routes, extraProps = {}, switchProps = {}) =>
+ routes ? (
+
+ {routes.map((route, i) => (
+ (
+
+ )}
+ />
+ ))}
+
+ ) : null;
-export default renderRoutes
+export default renderRoutes;
diff --git a/packages/react-router-config/rollup.config.js b/packages/react-router-config/rollup.config.js
index e92bdc184a..b6b70754ea 100644
--- a/packages/react-router-config/rollup.config.js
+++ b/packages/react-router-config/rollup.config.js
@@ -1,42 +1,42 @@
-import babel from 'rollup-plugin-babel'
-import uglify from 'rollup-plugin-uglify'
-import replace from 'rollup-plugin-replace'
-import commonjs from 'rollup-plugin-commonjs'
-import resolve from 'rollup-plugin-node-resolve'
+import babel from "rollup-plugin-babel";
+import uglify from "rollup-plugin-uglify";
+import replace from "rollup-plugin-replace";
+import commonjs from "rollup-plugin-commonjs";
+import resolve from "rollup-plugin-node-resolve";
const config = {
- input: 'modules/index.js',
- name: 'ReactRouterConfig',
+ input: "modules/index.js",
+ name: "ReactRouterConfig",
globals: {
- react: 'React',
- 'react-router/Switch': 'ReactRouter.Switch',
- 'react-router/Router': 'ReactRouter.Router',
- 'react-router/Route': 'ReactRouter.Route',
- 'react-router/matchPath': 'ReactRouter.matchPath',
+ react: "React",
+ "react-router/Switch": "ReactRouter.Switch",
+ "react-router/Router": "ReactRouter.Router",
+ "react-router/Route": "ReactRouter.Route",
+ "react-router/matchPath": "ReactRouter.matchPath"
},
external: [
- 'react',
- 'react-router/Switch',
- 'react-router/Router',
- 'react-router/Route',
- 'react-router/matchPath',
+ "react",
+ "react-router/Switch",
+ "react-router/Router",
+ "react-router/Route",
+ "react-router/matchPath"
],
plugins: [
babel({
- exclude: 'node_modules/**'
+ exclude: "node_modules/**"
}),
resolve(),
commonjs({
include: /node_modules/
}),
replace({
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
})
]
-}
+};
-if (process.env.NODE_ENV === 'production') {
- config.plugins.push(uglify())
+if (process.env.NODE_ENV === "production") {
+ config.plugins.push(uglify());
}
-export default config
+export default config;
diff --git a/packages/react-router-dom/modules/BrowserRouter.js b/packages/react-router-dom/modules/BrowserRouter.js
index e18f8ab576..3bf05d2f23 100644
--- a/packages/react-router-dom/modules/BrowserRouter.js
+++ b/packages/react-router-dom/modules/BrowserRouter.js
@@ -1,8 +1,8 @@
-import warning from 'warning'
-import React from 'react'
-import PropTypes from 'prop-types'
-import { createBrowserHistory as createHistory } from 'history'
-import Router from './Router'
+import warning from "warning";
+import React from "react";
+import PropTypes from "prop-types";
+import { createBrowserHistory as createHistory } from "history";
+import Router from "./Router";
/**
* The public API for a that uses HTML5 history.
@@ -14,21 +14,21 @@ class BrowserRouter extends React.Component {
getUserConfirmation: PropTypes.func,
keyLength: PropTypes.number,
children: PropTypes.node
- }
+ };
- history = createHistory(this.props)
+ history = createHistory(this.props);
componentWillMount() {
warning(
!this.props.history,
- ' ignores the history prop. To use a custom history, ' +
- 'use `import { Router }` instead of `import { BrowserRouter as Router }`.'
- )
+ " ignores the history prop. To use a custom history, " +
+ "use `import { Router }` instead of `import { BrowserRouter as Router }`."
+ );
}
render() {
- return
+ return ;
}
}
-export default BrowserRouter
+export default BrowserRouter;
diff --git a/packages/react-router-dom/modules/HashRouter.js b/packages/react-router-dom/modules/HashRouter.js
index 54f67033ca..26f822728b 100644
--- a/packages/react-router-dom/modules/HashRouter.js
+++ b/packages/react-router-dom/modules/HashRouter.js
@@ -1,8 +1,8 @@
-import warning from 'warning'
-import React from 'react'
-import PropTypes from 'prop-types'
-import { createHashHistory as createHistory } from 'history'
-import Router from './Router'
+import warning from "warning";
+import React from "react";
+import PropTypes from "prop-types";
+import { createHashHistory as createHistory } from "history";
+import Router from "./Router";
/**
* The public API for a that uses window.location.hash.
@@ -11,23 +11,23 @@ class HashRouter extends React.Component {
static propTypes = {
basename: PropTypes.string,
getUserConfirmation: PropTypes.func,
- hashType: PropTypes.oneOf([ 'hashbang', 'noslash', 'slash' ]),
+ hashType: PropTypes.oneOf(["hashbang", "noslash", "slash"]),
children: PropTypes.node
- }
+ };
- history = createHistory(this.props)
+ history = createHistory(this.props);
componentWillMount() {
warning(
!this.props.history,
- ' ignores the history prop. To use a custom history, ' +
- 'use `import { Router }` instead of `import { HashRouter as Router }`.'
- )
+ " ignores the history prop. To use a custom history, " +
+ "use `import { Router }` instead of `import { HashRouter as Router }`."
+ );
}
render() {
- return
+ return ;
}
}
-export default HashRouter
+export default HashRouter;
diff --git a/packages/react-router-dom/modules/Link.js b/packages/react-router-dom/modules/Link.js
index e522143d77..ff38db4676 100644
--- a/packages/react-router-dom/modules/Link.js
+++ b/packages/react-router-dom/modules/Link.js
@@ -1,10 +1,10 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import invariant from 'invariant'
-import { createLocation } from 'history'
+import React from "react";
+import PropTypes from "prop-types";
+import invariant from "invariant";
+import { createLocation } from "history";
-const isModifiedEvent = (event) =>
- !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
+const isModifiedEvent = event =>
+ !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
/**
* The public API for rendering a history-aware .
@@ -14,19 +14,13 @@ class Link extends React.Component {
onClick: PropTypes.func,
target: PropTypes.string,
replace: PropTypes.bool,
- to: PropTypes.oneOfType([
- PropTypes.string,
- PropTypes.object
- ]).isRequired,
- innerRef: PropTypes.oneOfType([
- PropTypes.string,
- PropTypes.func
- ])
- }
+ to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
+ innerRef: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
+ };
static defaultProps = {
replace: false
- }
+ };
static contextTypes = {
router: PropTypes.shape({
@@ -36,11 +30,10 @@ class Link extends React.Component {
createHref: PropTypes.func.isRequired
}).isRequired
}).isRequired
- }
+ };
- handleClick = (event) => {
- if (this.props.onClick)
- this.props.onClick(event)
+ handleClick = event => {
+ if (this.props.onClick) this.props.onClick(event);
if (
!event.defaultPrevented && // onClick prevented default
@@ -48,38 +41,40 @@ class Link extends React.Component {
!this.props.target && // let browser handle "target=_blank" etc.
!isModifiedEvent(event) // ignore clicks with modifier keys
) {
- event.preventDefault()
+ event.preventDefault();
- const { history } = this.context.router
- const { replace, to } = this.props
+ const { history } = this.context.router;
+ const { replace, to } = this.props;
if (replace) {
- history.replace(to)
+ history.replace(to);
} else {
- history.push(to)
+ history.push(to);
}
}
- }
+ };
render() {
- const { replace, to, innerRef, ...props } = this.props // eslint-disable-line no-unused-vars
+ const { replace, to, innerRef, ...props } = this.props; // eslint-disable-line no-unused-vars
invariant(
this.context.router,
- 'You should not use outside a '
- )
+ "You should not use outside a "
+ );
- invariant(
- to !== undefined,
- 'You must specify the "to" property'
- )
+ invariant(to !== undefined, 'You must specify the "to" property');
- const { history } = this.context.router
- const location = typeof to === 'string' ? createLocation(to, null, null, history.location) : to
+ const { history } = this.context.router;
+ const location =
+ typeof to === "string"
+ ? createLocation(to, null, null, history.location)
+ : to;
- const href = history.createHref(location)
- return
+ const href = history.createHref(location);
+ return (
+
+ );
}
}
-export default Link
+export default Link;
diff --git a/packages/react-router-dom/modules/MemoryRouter.js b/packages/react-router-dom/modules/MemoryRouter.js
index e3df710ae9..1a1983f2f2 100644
--- a/packages/react-router-dom/modules/MemoryRouter.js
+++ b/packages/react-router-dom/modules/MemoryRouter.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { MemoryRouter } from 'react-router'
-export default MemoryRouter
+import { MemoryRouter } from "react-router";
+export default MemoryRouter;
diff --git a/packages/react-router-dom/modules/NavLink.js b/packages/react-router-dom/modules/NavLink.js
index 3daa32b3b3..6a3051b11e 100644
--- a/packages/react-router-dom/modules/NavLink.js
+++ b/packages/react-router-dom/modules/NavLink.js
@@ -1,7 +1,7 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import Route from './Route'
-import Link from './Link'
+import React from "react";
+import PropTypes from "prop-types";
+import Route from "./Route";
+import Link from "./Link";
/**
* A wrapper that knows if it's "active" or not.
@@ -16,13 +16,13 @@ const NavLink = ({
activeStyle,
style,
isActive: getIsActive,
- 'aria-current': ariaCurrent,
+ "aria-current": ariaCurrent,
...rest
}) => {
- const path = typeof to === 'object' ? to.pathname : to
+ const path = typeof to === "object" ? to.pathname : to;
// Regex taken from: https://github.com/pillarjs/path-to-regexp/blob/master/index.js#L202
- const escapedPath = path.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1')
+ const escapedPath = path.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
return (
{
- const isActive = !!(getIsActive ? getIsActive(match, location) : match)
+ const isActive = !!(getIsActive ? getIsActive(match, location) : match);
return (
i).join(' ') : className}
+ className={
+ isActive
+ ? [className, activeClassName].filter(i => i).join(" ")
+ : className
+ }
style={isActive ? { ...style, ...activeStyle } : style}
- aria-current={isActive && ariaCurrent || null}
+ aria-current={(isActive && ariaCurrent) || null}
{...rest}
/>
- )
+ );
}}
/>
- )
-}
+ );
+};
NavLink.propTypes = {
to: Link.propTypes.to,
@@ -57,12 +61,19 @@ NavLink.propTypes = {
activeStyle: PropTypes.object,
style: PropTypes.object,
isActive: PropTypes.func,
- 'aria-current': PropTypes.oneOf(['page', 'step', 'location', 'date', 'time', 'true'])
-}
+ "aria-current": PropTypes.oneOf([
+ "page",
+ "step",
+ "location",
+ "date",
+ "time",
+ "true"
+ ])
+};
NavLink.defaultProps = {
- activeClassName: 'active',
- 'aria-current': 'true'
-}
+ activeClassName: "active",
+ "aria-current": "true"
+};
-export default NavLink
+export default NavLink;
diff --git a/packages/react-router-dom/modules/Prompt.js b/packages/react-router-dom/modules/Prompt.js
index 206d983109..a4a8929735 100644
--- a/packages/react-router-dom/modules/Prompt.js
+++ b/packages/react-router-dom/modules/Prompt.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { Prompt } from 'react-router'
-export default Prompt
+import { Prompt } from "react-router";
+export default Prompt;
diff --git a/packages/react-router-dom/modules/Redirect.js b/packages/react-router-dom/modules/Redirect.js
index 3da36cc3e0..47d5b7e6ce 100644
--- a/packages/react-router-dom/modules/Redirect.js
+++ b/packages/react-router-dom/modules/Redirect.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { Redirect } from 'react-router'
-export default Redirect
+import { Redirect } from "react-router";
+export default Redirect;
diff --git a/packages/react-router-dom/modules/Route.js b/packages/react-router-dom/modules/Route.js
index 2d3a1ad16e..e4f048300e 100644
--- a/packages/react-router-dom/modules/Route.js
+++ b/packages/react-router-dom/modules/Route.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { Route } from 'react-router'
-export default Route
\ No newline at end of file
+import { Route } from "react-router";
+export default Route;
diff --git a/packages/react-router-dom/modules/Router.js b/packages/react-router-dom/modules/Router.js
index 18d713a2ac..8c489f2b3d 100644
--- a/packages/react-router-dom/modules/Router.js
+++ b/packages/react-router-dom/modules/Router.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { Router } from 'react-router'
-export default Router
\ No newline at end of file
+import { Router } from "react-router";
+export default Router;
diff --git a/packages/react-router-dom/modules/StaticRouter.js b/packages/react-router-dom/modules/StaticRouter.js
index 43e27a7f2d..c5cfe59add 100644
--- a/packages/react-router-dom/modules/StaticRouter.js
+++ b/packages/react-router-dom/modules/StaticRouter.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { StaticRouter } from 'react-router'
-export default StaticRouter
\ No newline at end of file
+import { StaticRouter } from "react-router";
+export default StaticRouter;
diff --git a/packages/react-router-dom/modules/Switch.js b/packages/react-router-dom/modules/Switch.js
index 61cfaec35d..8947bd6f31 100644
--- a/packages/react-router-dom/modules/Switch.js
+++ b/packages/react-router-dom/modules/Switch.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { Switch } from 'react-router'
-export default Switch
\ No newline at end of file
+import { Switch } from "react-router";
+export default Switch;
diff --git a/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js b/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js
index c0ae698531..a4a594cba5 100644
--- a/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js
+++ b/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js
@@ -1,44 +1,43 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import PropTypes from 'prop-types'
-import BrowserRouter from '../BrowserRouter'
-
-describe('A ', () => {
- it('puts history on context.router', () => {
- let history
+import React from "react";
+import ReactDOM from "react-dom";
+import PropTypes from "prop-types";
+import BrowserRouter from "../BrowserRouter";
+
+describe("A ", () => {
+ it("puts history on context.router", () => {
+ let history;
const ContextChecker = (props, context) => {
- history = context.router.history
- return null
- }
+ history = context.router.history;
+ return null;
+ };
ContextChecker.contextTypes = {
router: PropTypes.object.isRequired
- }
+ };
- const node = document.createElement('div')
+ const node = document.createElement("div");
- ReactDOM.render((
+ ReactDOM.render(
-
-
- ), node)
+
+ ,
+ node
+ );
- expect(typeof history).toBe('object')
- })
+ expect(typeof history).toBe("object");
+ });
- it('warns when passed a history prop', () => {
- const history = {}
- const node = document.createElement('div')
+ it("warns when passed a history prop", () => {
+ const history = {};
+ const node = document.createElement("div");
- spyOn(console, 'error')
+ spyOn(console, "error");
- ReactDOM.render((
-
- ), node)
+ ReactDOM.render(, node);
- expect(console.error).toHaveBeenCalledTimes(1)
+ expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error).toHaveBeenCalledWith(
- expect.stringContaining(' ignores the history prop')
- )
- })
-})
+ expect.stringContaining(" ignores the history prop")
+ );
+ });
+});
diff --git a/packages/react-router-dom/modules/__tests__/HashRouter-test.js b/packages/react-router-dom/modules/__tests__/HashRouter-test.js
index 22bea95898..2bcc25578b 100644
--- a/packages/react-router-dom/modules/__tests__/HashRouter-test.js
+++ b/packages/react-router-dom/modules/__tests__/HashRouter-test.js
@@ -1,44 +1,43 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import PropTypes from 'prop-types'
-import HashRouter from '../HashRouter'
-
-describe('A ', () => {
- it('puts history on context.router', () => {
- let history
+import React from "react";
+import ReactDOM from "react-dom";
+import PropTypes from "prop-types";
+import HashRouter from "../HashRouter";
+
+describe("A ", () => {
+ it("puts history on context.router", () => {
+ let history;
const ContextChecker = (props, context) => {
- history = context.router.history
- return null
- }
+ history = context.router.history;
+ return null;
+ };
ContextChecker.contextTypes = {
router: PropTypes.object.isRequired
- }
+ };
- const node = document.createElement('div')
+ const node = document.createElement("div");
- ReactDOM.render((
+ ReactDOM.render(
-
-
- ), node)
+
+ ,
+ node
+ );
- expect(typeof history).toBe('object')
- })
+ expect(typeof history).toBe("object");
+ });
- it('warns when passed a history prop', () => {
- const history = {}
- const node = document.createElement('div')
+ it("warns when passed a history prop", () => {
+ const history = {};
+ const node = document.createElement("div");
- spyOn(console, 'error')
+ spyOn(console, "error");
- ReactDOM.render((
-
- ), node)
+ ReactDOM.render(, node);
- expect(console.error).toHaveBeenCalledTimes(1)
+ expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error).toHaveBeenCalledWith(
- expect.stringContaining(' ignores the history prop')
- )
- })
-})
+ expect.stringContaining(" ignores the history prop")
+ );
+ });
+});
diff --git a/packages/react-router-dom/modules/__tests__/Link-test.js b/packages/react-router-dom/modules/__tests__/Link-test.js
index 91bdf2e3fc..6f65b038f8 100644
--- a/packages/react-router-dom/modules/__tests__/Link-test.js
+++ b/packages/react-router-dom/modules/__tests__/Link-test.js
@@ -1,159 +1,163 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import MemoryRouter from 'react-router/MemoryRouter'
-import HashRouter from '../HashRouter'
-import Link from '../Link'
+import React from "react";
+import ReactDOM from "react-dom";
+import MemoryRouter from "react-router/MemoryRouter";
+import HashRouter from "../HashRouter";
+import Link from "../Link";
-describe('A ', () => {
+describe("A ", () => {
it('accepts a location "to" prop', () => {
const location = {
- pathname: '/the/path',
- search: 'the=query',
- hash: '#the-hash'
- }
- const node = document.createElement('div')
+ pathname: "/the/path",
+ search: "the=query",
+ hash: "#the-hash"
+ };
+ const node = document.createElement("div");
- ReactDOM.render((
+ ReactDOM.render(
link
-
- ), node)
+ ,
+ node
+ );
- const href = node.querySelector('a').getAttribute('href')
+ const href = node.querySelector("a").getAttribute("href");
- expect(href).toEqual('/the/path?the=query#the-hash')
- })
+ expect(href).toEqual("/the/path?the=query#the-hash");
+ });
- describe('to as a string', () => {
- it('resolves to with no pathname using current location', () => {
- const node = document.createElement('div')
+ describe("to as a string", () => {
+ it("resolves to with no pathname using current location", () => {
+ const node = document.createElement("div");
- ReactDOM.render((
-
- link
-
- ), node)
+ ReactDOM.render(
+
+ link
+ ,
+ node
+ );
- const href = node.querySelector('a').getAttribute('href')
+ const href = node.querySelector("a").getAttribute("href");
- expect(href).toEqual('/somewhere?rendersWithPathname=true')
- })
- })
+ expect(href).toEqual("/somewhere?rendersWithPathname=true");
+ });
+ });
- it('throws with no ', () => {
- const node = document.createElement('div')
+ it("throws with no ", () => {
+ const node = document.createElement("div");
- spyOn(console, 'error')
+ spyOn(console, "error");
expect(() => {
- ReactDOM.render((
- link
- ), node)
- }).toThrow(/You should not use outside a /)
+ ReactDOM.render(link, node);
+ }).toThrow(/You should not use outside a /);
- expect(console.error.calls.count()).toBe(2)
+ expect(console.error.calls.count()).toBe(2);
expect(console.error.calls.argsFor(0)[0]).toContain(
- 'The context `router` is marked as required in `Link`'
- )
- })
+ "The context `router` is marked as required in `Link`"
+ );
+ });
it('throws with no "to" prop', () => {
- const node = document.createElement('div')
+ const node = document.createElement("div");
- spyOn(console, 'error')
+ spyOn(console, "error");
expect(() => {
- ReactDOM.render((
+ ReactDOM.render(
link
-
- ), node)
- }).toThrow(/You must specify the "to" property/)
+ ,
+ node
+ );
+ }).toThrow(/You must specify the "to" property/);
- expect(console.error.calls.count()).toBe(2)
+ expect(console.error.calls.count()).toBe(2);
expect(console.error.calls.argsFor(0)[0]).toContain(
- 'The prop `to` is marked as required in `Link`'
- )
- })
+ "The prop `to` is marked as required in `Link`"
+ );
+ });
- it('exposes its ref via an innerRef prop', done => {
- const node = document.createElement('div')
+ it("exposes its ref via an innerRef prop", done => {
+ const node = document.createElement("div");
const refCallback = n => {
- expect(n.tagName).toEqual('A')
- done()
- }
+ expect(n.tagName).toEqual("A");
+ done();
+ };
ReactDOM.render(
- link
+
+ link
+
,
node
- )
- })
-})
+ );
+ });
+});
-describe('When a is clicked', () => {
- it('calls its onClick handler')
+describe("When a is clicked", () => {
+ it("calls its onClick handler");
- it('changes the location')
+ it("changes the location");
- describe('and the onClick handler calls event.preventDefault()', () => {
- it('does not change the location')
- })
-})
+ describe("and the onClick handler calls event.preventDefault()", () => {
+ it("does not change the location");
+ });
+});
-describe('A underneath a ', () => {
- const node = document.createElement('div')
+describe("A underneath a ", () => {
+ const node = document.createElement("div");
afterEach(() => {
- ReactDOM.unmountComponentAtNode(node)
- window.history.replaceState(null, '', '#')
- })
+ ReactDOM.unmountComponentAtNode(node);
+ window.history.replaceState(null, "", "#");
+ });
const createLinkNode = (hashType, to) => {
- ReactDOM.render((
+ ReactDOM.render(
-
-
- ), node)
+
+ ,
+ node
+ );
- return node.querySelector('a')
- }
+ return node.querySelector("a");
+ };
describe('with the "slash" hashType', () => {
- it('has the correct href', () => {
- const linkNode = createLinkNode('slash', '/foo')
- expect(linkNode.getAttribute('href')).toEqual('#/foo')
- })
+ it("has the correct href", () => {
+ const linkNode = createLinkNode("slash", "/foo");
+ expect(linkNode.getAttribute("href")).toEqual("#/foo");
+ });
- it('has the correct href with a leading slash if it is missing', () => {
- const linkNode = createLinkNode('slash', 'foo')
- expect(linkNode.getAttribute('href')).toEqual('#/foo')
- })
- })
+ it("has the correct href with a leading slash if it is missing", () => {
+ const linkNode = createLinkNode("slash", "foo");
+ expect(linkNode.getAttribute("href")).toEqual("#/foo");
+ });
+ });
describe('with the "hashbang" hashType', () => {
- it('has the correct href', () => {
- const linkNode = createLinkNode('hashbang', '/foo')
- expect(linkNode.getAttribute('href')).toEqual('#!/foo')
- })
+ it("has the correct href", () => {
+ const linkNode = createLinkNode("hashbang", "/foo");
+ expect(linkNode.getAttribute("href")).toEqual("#!/foo");
+ });
- it('has the correct href with a leading slash if it is missing', () => {
- const linkNode = createLinkNode('hashbang', 'foo')
- expect(linkNode.getAttribute('href')).toEqual('#!/foo')
- })
- })
+ it("has the correct href with a leading slash if it is missing", () => {
+ const linkNode = createLinkNode("hashbang", "foo");
+ expect(linkNode.getAttribute("href")).toEqual("#!/foo");
+ });
+ });
describe('with the "noslash" hashType', () => {
- it('has the correct href', () => {
- const linkNode = createLinkNode('noslash', 'foo')
- expect(linkNode.getAttribute('href')).toEqual('#foo')
- })
-
- it('has the correct href and removes the leading slash', () => {
- const linkNode = createLinkNode('noslash', '/foo')
- expect(linkNode.getAttribute('href')).toEqual('#foo')
- })
- })
-})
+ it("has the correct href", () => {
+ const linkNode = createLinkNode("noslash", "foo");
+ expect(linkNode.getAttribute("href")).toEqual("#foo");
+ });
+
+ it("has the correct href and removes the leading slash", () => {
+ const linkNode = createLinkNode("noslash", "/foo");
+ expect(linkNode.getAttribute("href")).toEqual("#foo");
+ });
+ });
+});
diff --git a/packages/react-router-dom/modules/__tests__/NavLink-test.js b/packages/react-router-dom/modules/__tests__/NavLink-test.js
index 65ef3e249a..cf7a06d42f 100644
--- a/packages/react-router-dom/modules/__tests__/NavLink-test.js
+++ b/packages/react-router-dom/modules/__tests__/NavLink-test.js
@@ -1,352 +1,399 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import MemoryRouter from 'react-router/MemoryRouter'
-import NavLink from '../NavLink'
+import React from "react";
+import ReactDOM from "react-dom";
+import MemoryRouter from "react-router/MemoryRouter";
+import NavLink from "../NavLink";
-describe('NavLink', () => {
- const node = document.createElement('div')
+describe("NavLink", () => {
+ const node = document.createElement("div");
afterEach(() => {
- ReactDOM.unmountComponentAtNode(node)
- })
-
- describe('When a is active', () => {
- it('applies its default activeClassName', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).toEqual('active')
- })
-
- it('applies its passed activeClassName', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).toEqual('selected')
- })
-
- it('applies its activeStyle', () => {
- const defaultStyle = { color: 'black' }
- const activeStyle = { color: 'red' }
-
- ReactDOM.render((
-
-
+ ReactDOM.unmountComponentAtNode(node);
+ });
+
+ describe("When a is active", () => {
+ it("applies its default activeClassName", () => {
+ ReactDOM.render(
+
+ Pizza!
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).toEqual("active");
+ });
+
+ it("applies its passed activeClassName", () => {
+ ReactDOM.render(
+
+
Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.style.color).toBe(activeStyle.color)
- })
-
- it('applies aria-current of true if no override value is given', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.getAttribute('aria-current')).toEqual('true')
- })
-
- it('applies the override aria-current value when given', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.getAttribute('aria-current')).toEqual('page')
- })
-
- it('it properly escapes path-to-regexp special characters', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
-
- const href = node.querySelector('a').getAttribute('href')
- expect(href).toEqual('/pizza (1)')
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).toEqual('active')
- })
- })
-
- describe('When a is not active', () => {
- it('does not apply its default activeClassName', () => {
- ReactDOM.render((
-
- Salad?
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- })
-
- it('does not apply its passed activeClassName', () => {
- ReactDOM.render((
-
- Salad?
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).not.toContain('selected')
- })
-
- it('does not apply its activeStyle', () => {
- const defaultStyle = { color: 'black' }
- const activeStyle = { color: 'red' }
-
- ReactDOM.render((
-
-
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).toEqual("selected");
+ });
+
+ it("applies its activeStyle", () => {
+ const defaultStyle = { color: "black" };
+ const activeStyle = { color: "red" };
+
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.style.color).toBe(activeStyle.color);
+ });
+
+ it("applies aria-current of true if no override value is given", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.getAttribute("aria-current")).toEqual("true");
+ });
+
+ it("applies the override aria-current value when given", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.getAttribute("aria-current")).toEqual("page");
+ });
+
+ it("it properly escapes path-to-regexp special characters", () => {
+ ReactDOM.render(
+
+ Pizza!
+ ,
+ node
+ );
+
+ const href = node.querySelector("a").getAttribute("href");
+ expect(href).toEqual("/pizza (1)");
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).toEqual("active");
+ });
+ });
+
+ describe("When a is not active", () => {
+ it("does not apply its default activeClassName", () => {
+ ReactDOM.render(
+
+ Salad?
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ });
+
+ it("does not apply its passed activeClassName", () => {
+ ReactDOM.render(
+
+
Salad?
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.style.color).toBe(defaultStyle.color)
- })
-
- it('does not apply an aria-current value if no override value is given', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.getAttribute('aria-current')).toBeNull()
- })
-
- it('does not apply an aria-current value if an override value is given', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.getAttribute('aria-current')).toBeNull()
- })
- })
-
- describe('isActive', () => {
- it('applies active default props when isActive returns true', () => {
- ReactDOM.render((
-
- true}
- >
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).not.toContain("selected");
+ });
+
+ it("does not apply its activeStyle", () => {
+ const defaultStyle = { color: "black" };
+ const activeStyle = { color: "red" };
+
+ ReactDOM.render(
+
+
+ Salad?
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.style.color).toBe(defaultStyle.color);
+ });
+
+ it("does not apply an aria-current value if no override value is given", () => {
+ ReactDOM.render(
+
+
Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).toEqual('active')
- })
-
- it('applies active passed props when isActive returns true', () => {
- ReactDOM.render((
-
- true}
- >
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.getAttribute("aria-current")).toBeNull();
+ });
+
+ it("does not apply an aria-current value if an override value is given", () => {
+ ReactDOM.render(
+
+
Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).toEqual('selected')
- })
-
- it('does not apply active default props when isActive returns false', () => {
- ReactDOM.render((
-
- false}
- >
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.getAttribute("aria-current")).toBeNull();
+ });
+ });
+
+ describe("isActive", () => {
+ it("applies active default props when isActive returns true", () => {
+ ReactDOM.render(
+
+ true}>
Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- })
-
- it('does not apply active passed props when isActive returns false', () => {
- ReactDOM.render((
-
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).toEqual("active");
+ });
+
+ it("applies active passed props when isActive returns true", () => {
+ ReactDOM.render(
+
+ true}>
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).toEqual("selected");
+ });
+
+ it("does not apply active default props when isActive returns false", () => {
+ ReactDOM.render(
+
+ false}>
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ });
+
+ it("does not apply active passed props when isActive returns false", () => {
+ ReactDOM.render(
+ false}
- >
+ >
Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).not.toContain('selected')
- })
- })
-
- describe('exact', () => {
- it('does not do exact matching by default', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).toEqual('active')
- })
-
- it('sets active default value only for exact matches', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).toEqual('active')
- })
-
- it('sets active passed value only for exact matches', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).toEqual('selected')
- })
-
- it('does not set active default value for partial matches', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- })
-
- it('does not set active passed value for partial matches', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).not.toContain('selected')
- })
- })
-
- describe('strict (enforce path\'s trailing slash)', () => {
- const PATH = '/pizza/'
- it('does not do strict matching by default', () => {
- ReactDOM.render((
-
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).not.toContain("selected");
+ });
+ });
+
+ describe("exact", () => {
+ it("does not do exact matching by default", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).toEqual("active");
+ });
+
+ it("sets active default value only for exact matches", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).toEqual("active");
+ });
+
+ it("sets active passed value only for exact matches", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).toEqual("selected");
+ });
+
+ it("does not set active default value for partial matches", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ });
+
+ it("does not set active passed value for partial matches", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).not.toContain("selected");
+ });
+ });
+
+ describe("strict (enforce path's trailing slash)", () => {
+ const PATH = "/pizza/";
+ it("does not do strict matching by default", () => {
+ ReactDOM.render(
+ Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).toEqual('active')
- })
-
- it('does not set active default value when location.pathname has no trailing slash', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- })
-
- it('does not set active passed value when location.pathname has no trailing slash', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).not.toContain('selected')
- })
-
- it('sets active default value when pathname has trailing slash', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).toEqual('active')
- })
-
- it('sets active passed value when pathname has trailing slash', () => {
- ReactDOM.render((
-
- Pizza!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).toEqual('selected')
- })
- })
-
- describe('location property', () => {
- it('overrides the current location', () => {
- ReactDOM.render((
-
- Pasta!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).toContain('selected')
- })
-
- it('is not overwritten by the current location', () => {
- ReactDOM.render((
-
- Pasta!
-
- ), node)
- const a = node.getElementsByTagName('a')[0]
- expect(a.className).not.toContain('active')
- expect(a.className).not.toContain('selected')
- })
- })
-})
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).toEqual("active");
+ });
+
+ it("does not set active default value when location.pathname has no trailing slash", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ });
+
+ it("does not set active passed value when location.pathname has no trailing slash", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).not.toContain("selected");
+ });
+
+ it("sets active default value when pathname has trailing slash", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).toEqual("active");
+ });
+
+ it("sets active passed value when pathname has trailing slash", () => {
+ ReactDOM.render(
+
+
+ Pizza!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).toEqual("selected");
+ });
+ });
+
+ describe("location property", () => {
+ it("overrides the current location", () => {
+ ReactDOM.render(
+
+
+ Pasta!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).toContain("selected");
+ });
+
+ it("is not overwritten by the current location", () => {
+ ReactDOM.render(
+
+
+ Pasta!
+
+ ,
+ node
+ );
+ const a = node.getElementsByTagName("a")[0];
+ expect(a.className).not.toContain("active");
+ expect(a.className).not.toContain("selected");
+ });
+ });
+});
diff --git a/packages/react-router-dom/modules/generatePath.js b/packages/react-router-dom/modules/generatePath.js
index 790adaa90e..b4b3ee990e 100644
--- a/packages/react-router-dom/modules/generatePath.js
+++ b/packages/react-router-dom/modules/generatePath.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { generatePath } from 'react-router'
-export default generatePath
+import { generatePath } from "react-router";
+export default generatePath;
diff --git a/packages/react-router-dom/modules/index.js b/packages/react-router-dom/modules/index.js
index fb204e116b..789599ad00 100644
--- a/packages/react-router-dom/modules/index.js
+++ b/packages/react-router-dom/modules/index.js
@@ -1,14 +1,14 @@
-export BrowserRouter from './BrowserRouter'
-export HashRouter from './HashRouter'
-export Link from './Link'
-export MemoryRouter from './MemoryRouter'
-export NavLink from './NavLink'
-export Prompt from './Prompt'
-export Redirect from './Redirect'
-export Route from './Route'
-export Router from './Router'
-export StaticRouter from './StaticRouter'
-export Switch from './Switch'
-export generatePath from './generatePath'
-export matchPath from './matchPath'
-export withRouter from './withRouter'
+export BrowserRouter from "./BrowserRouter";
+export HashRouter from "./HashRouter";
+export Link from "./Link";
+export MemoryRouter from "./MemoryRouter";
+export NavLink from "./NavLink";
+export Prompt from "./Prompt";
+export Redirect from "./Redirect";
+export Route from "./Route";
+export Router from "./Router";
+export StaticRouter from "./StaticRouter";
+export Switch from "./Switch";
+export generatePath from "./generatePath";
+export matchPath from "./matchPath";
+export withRouter from "./withRouter";
diff --git a/packages/react-router-dom/modules/matchPath.js b/packages/react-router-dom/modules/matchPath.js
index 8f4e4d7d98..854585ea8b 100644
--- a/packages/react-router-dom/modules/matchPath.js
+++ b/packages/react-router-dom/modules/matchPath.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { matchPath } from 'react-router'
-export default matchPath
+import { matchPath } from "react-router";
+export default matchPath;
diff --git a/packages/react-router-dom/modules/withRouter.js b/packages/react-router-dom/modules/withRouter.js
index d450f64339..5cf0b2f92d 100644
--- a/packages/react-router-dom/modules/withRouter.js
+++ b/packages/react-router-dom/modules/withRouter.js
@@ -1,3 +1,3 @@
// Written in this round about way for babel-transform-imports
-import { withRouter } from 'react-router'
-export default withRouter
+import { withRouter } from "react-router";
+export default withRouter;
diff --git a/packages/react-router-dom/rollup.config.js b/packages/react-router-dom/rollup.config.js
index 1fc2c07084..00d4165d97 100644
--- a/packages/react-router-dom/rollup.config.js
+++ b/packages/react-router-dom/rollup.config.js
@@ -1,38 +1,36 @@
-import babel from 'rollup-plugin-babel'
-import uglify from 'rollup-plugin-uglify'
-import replace from 'rollup-plugin-replace'
-import commonjs from 'rollup-plugin-commonjs'
-import resolve from 'rollup-plugin-node-resolve'
+import babel from "rollup-plugin-babel";
+import uglify from "rollup-plugin-uglify";
+import replace from "rollup-plugin-replace";
+import commonjs from "rollup-plugin-commonjs";
+import resolve from "rollup-plugin-node-resolve";
const config = {
- input: 'modules/index.js',
- name: 'ReactRouterDOM',
+ input: "modules/index.js",
+ name: "ReactRouterDOM",
globals: {
- react: 'React'
+ react: "React"
},
- external: [
- 'react'
- ],
+ external: ["react"],
plugins: [
babel({
- exclude: 'node_modules/**'
+ exclude: "node_modules/**"
}),
resolve({
customResolveOptions: {
- moduleDirectory: ['../../node_modules', '../']
+ moduleDirectory: ["../../node_modules", "../"]
}
}),
commonjs({
include: /node_modules/
}),
replace({
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
})
]
-}
+};
-if (process.env.NODE_ENV === 'production') {
- config.plugins.push(uglify())
+if (process.env.NODE_ENV === "production") {
+ config.plugins.push(uglify());
}
-export default config
+export default config;
diff --git a/packages/react-router-native/BackButton.js b/packages/react-router-native/BackButton.js
index f370343b2c..08250b5e06 100644
--- a/packages/react-router-native/BackButton.js
+++ b/packages/react-router-native/BackButton.js
@@ -1,6 +1,6 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import { BackHandler } from 'react-native'
+import React from "react";
+import PropTypes from "prop-types";
+import { BackHandler } from "react-native";
class BackButton extends React.Component {
static contextTypes = {
@@ -10,30 +10,30 @@ class BackButton extends React.Component {
index: PropTypes.number.isRequired
}).isRequired
}).isRequired
- }
+ };
componentDidMount() {
- BackHandler.addEventListener('hardwareBackPress', this.handleBack)
+ BackHandler.addEventListener("hardwareBackPress", this.handleBack);
}
componentWillUnmount() {
- BackHandler.removeEventListener('hardwareBackPress', this.handleBack)
+ BackHandler.removeEventListener("hardwareBackPress", this.handleBack);
}
handleBack = () => {
- const { history } = this.context.router
+ const { history } = this.context.router;
if (history.index === 0) {
- return false // home screen
+ return false; // home screen
} else {
- history.goBack()
- return true
+ history.goBack();
+ return true;
}
- }
+ };
render() {
- return this.props.children || null
+ return this.props.children || null;
}
}
-export default BackButton
+export default BackButton;
diff --git a/packages/react-router-native/DeepLinking.js b/packages/react-router-native/DeepLinking.js
index 2c620ca611..120650c055 100644
--- a/packages/react-router-native/DeepLinking.js
+++ b/packages/react-router-native/DeepLinking.js
@@ -1,8 +1,8 @@
-import React, { Component } from 'react'
-import PropTypes from 'prop-types'
-import { Linking } from 'react-native'
+import React, { Component } from "react";
+import PropTypes from "prop-types";
+import { Linking } from "react-native";
-const regex = /.*?:\/\//g
+const regex = /.*?:\/\//g;
class DeepLinking extends Component {
static contextTypes = {
@@ -11,31 +11,30 @@ class DeepLinking extends Component {
push: PropTypes.func.isRequired
}).isRequired
}).isRequired
- }
+ };
async componentDidMount() {
- const url = await Linking.getInitialURL()
- if (url)
- this.push(url)
- Linking.addEventListener('url', this.handleChange)
+ const url = await Linking.getInitialURL();
+ if (url) this.push(url);
+ Linking.addEventListener("url", this.handleChange);
}
componentWillUnmount() {
- Linking.removeEventListener('url', this.handleChange)
+ Linking.removeEventListener("url", this.handleChange);
}
- handleChange = (e) => {
- this.push(e.url)
- }
+ handleChange = e => {
+ this.push(e.url);
+ };
- push = (url) => {
- const pathname = url.replace(regex, '')
- this.context.router.history.push(pathname)
- }
+ push = url => {
+ const pathname = url.replace(regex, "");
+ this.context.router.history.push(pathname);
+ };
render() {
return this.props.children || null;
}
}
-export default DeepLinking
+export default DeepLinking;
diff --git a/packages/react-router-native/Link.js b/packages/react-router-native/Link.js
index 8b21b34bf1..f36437b026 100644
--- a/packages/react-router-native/Link.js
+++ b/packages/react-router-native/Link.js
@@ -1,6 +1,6 @@
-import React, { Component } from 'react'
-import PropTypes from 'prop-types'
-import { TouchableHighlight } from 'react-native'
+import React, { Component } from "react";
+import PropTypes from "prop-types";
+import { TouchableHighlight } from "react-native";
class Link extends Component {
static contextTypes = {
@@ -10,43 +10,39 @@ class Link extends Component {
replace: PropTypes.func.isRequired
}).isRequired
}).isRequired
- }
+ };
static propTypes = {
onPress: PropTypes.func,
component: PropTypes.func,
replace: PropTypes.bool,
- to: PropTypes.oneOfType([
- PropTypes.string,
- PropTypes.object
- ])
- }
+ to: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
+ };
static defaultProps = {
component: TouchableHighlight,
replace: false
- }
+ };
- handlePress = (event) => {
- if (this.props.onPress)
- this.props.onPress(event)
+ handlePress = event => {
+ if (this.props.onPress) this.props.onPress(event);
if (!event.defaultPrevented) {
- const { history } = this.context.router
- const { to, replace } = this.props
+ const { history } = this.context.router;
+ const { to, replace } = this.props;
if (replace) {
- history.replace(to)
+ history.replace(to);
} else {
- history.push(to)
+ history.push(to);
}
}
- }
+ };
render() {
- const { component: Component, to, replace, ...rest } = this.props
- return
+ const { component: Component, to, replace, ...rest } = this.props;
+ return ;
}
}
-export default Link
+export default Link;
diff --git a/packages/react-router-native/NativeRouter.js b/packages/react-router-native/NativeRouter.js
index c2b3ad1312..927d20cd9d 100644
--- a/packages/react-router-native/NativeRouter.js
+++ b/packages/react-router-native/NativeRouter.js
@@ -1,15 +1,13 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import MemoryRouter from 'react-router/MemoryRouter'
-import { Alert } from 'react-native'
+import React from "react";
+import PropTypes from "prop-types";
+import MemoryRouter from "react-router/MemoryRouter";
+import { Alert } from "react-native";
/**
* The public API for a designed for React Native. Gets
* user confirmations via Alert by default.
*/
-const NativeRouter = (props) => (
-
-)
+const NativeRouter = props => ;
NativeRouter.propTypes = {
initialEntries: PropTypes.array,
@@ -17,15 +15,15 @@ NativeRouter.propTypes = {
getUserConfirmation: PropTypes.func,
keyLength: PropTypes.number,
children: PropTypes.node
-}
+};
NativeRouter.defaultProps = {
getUserConfirmation: (message, callback) => {
- Alert.alert('Confirm', message, [
- { text: 'Cancel', onPress: () => callback(false) },
- { text: 'OK', onPress: () => callback(true) }
- ])
+ Alert.alert("Confirm", message, [
+ { text: "Cancel", onPress: () => callback(false) },
+ { text: "OK", onPress: () => callback(true) }
+ ]);
}
-}
+};
-export default NativeRouter
+export default NativeRouter;
diff --git a/packages/react-router-native/index.android.js b/packages/react-router-native/index.android.js
index 2c8b0991a0..6594cbe7c4 100644
--- a/packages/react-router-native/index.android.js
+++ b/packages/react-router-native/index.android.js
@@ -1,65 +1,74 @@
-import React from 'react'
-import { AppRegistry, StyleSheet, Text, View } from 'react-native'
+import React from "react";
+import { AppRegistry, StyleSheet, Text, View } from "react-native";
-import { NativeRouter, Route, Link, DeepLinking, BackButton, Prompt } from './main'
+import {
+ NativeRouter,
+ Route,
+ Link,
+ DeepLinking,
+ BackButton,
+ Prompt
+} from "./main";
export default class ReactRouterNative extends React.Component {
render() {
return (
-
-
+
+
- (
-
-
- Welcome to React Router Native!
-
-
-
- Go to "/one"
+ (
+
+
+ Welcome to React Router Native!
-
-
- )}/>
+
+ Go to "/one"
+
+
+ )}
+ />
- (
-
-
-
- ONE! {match.url}
-
-
-
- Go Back
-
-
-
- )}/>
+ (
+
+
+ ONE! {match.url}
+
+ Go Back
+
+
+ )}
+ />
- )
+ );
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: '#F5FCFF',
+ justifyContent: "center",
+ alignItems: "center",
+ backgroundColor: "#F5FCFF"
},
welcome: {
fontSize: 20,
- textAlign: 'center',
- margin: 10,
+ textAlign: "center",
+ margin: 10
},
instructions: {
- textAlign: 'center',
- color: '#333333',
- marginBottom: 5,
+ textAlign: "center",
+ color: "#333333",
+ marginBottom: 5
}
-})
+});
-AppRegistry.registerComponent('ReactRouterNative', () => ReactRouterNative)
+AppRegistry.registerComponent("ReactRouterNative", () => ReactRouterNative);
diff --git a/packages/react-router-native/index.ios.js b/packages/react-router-native/index.ios.js
index 5805678c54..8aed3af6c1 100644
--- a/packages/react-router-native/index.ios.js
+++ b/packages/react-router-native/index.ios.js
@@ -1,8 +1,8 @@
-import { AppRegistry } from 'react-native'
+import { AppRegistry } from "react-native";
-import ReactRouterNative from './examples/BasicExample'
+import ReactRouterNative from "./examples/BasicExample";
//import ReactRouterNative from './examples/ExperimentalExample'
-export default ReactRouterNative
+export default ReactRouterNative;
-AppRegistry.registerComponent('ReactRouterNative', () => ReactRouterNative)
+AppRegistry.registerComponent("ReactRouterNative", () => ReactRouterNative);
diff --git a/packages/react-router-native/main.js b/packages/react-router-native/main.js
index 7a17cd003c..7cb6e99e42 100644
--- a/packages/react-router-native/main.js
+++ b/packages/react-router-native/main.js
@@ -1,9 +1,9 @@
-export * from 'react-router'
+export * from "react-router";
-import BackButton from './BackButton'
-import DeepLinking from './DeepLinking'
-import Link from './Link'
-import NativeRouter from './NativeRouter'
+import BackButton from "./BackButton";
+import DeepLinking from "./DeepLinking";
+import Link from "./Link";
+import NativeRouter from "./NativeRouter";
export {
BackButton,
@@ -11,4 +11,4 @@ export {
DeepLinking,
Link,
NativeRouter
-}
+};
diff --git a/packages/react-router-native/rn-cli.config.js b/packages/react-router-native/rn-cli.config.js
index 9b3ac28157..13a895c301 100644
--- a/packages/react-router-native/rn-cli.config.js
+++ b/packages/react-router-native/rn-cli.config.js
@@ -1,13 +1,21 @@
-const path = require('path');
-const blacklist = require('react-native/packager/blacklist');
-const config = require('react-native/packager/rn-cli.config');
+const path = require("path");
+const blacklist = require("react-native/packager/blacklist");
+const config = require("react-native/packager/rn-cli.config");
-const rootPackagePath = path.join(__dirname, '..', '..');
+const rootPackagePath = path.join(__dirname, "..", "..");
config.getBlacklist = () => [
new RegExp(`^${escapeRegExp(rootPackagePath)}\/node_modules(.*)`),
- new RegExp(`^${escapeRegExp(rootPackagePath)}\/packages\/(react-router-dom|react-router-website(-*)?)\/(.*)`),
- new RegExp(`^${escapeRegExp(rootPackagePath)}\/packages\/react-router-native\/node_modules\/react-router(.*)`),
+ new RegExp(
+ `^${escapeRegExp(
+ rootPackagePath
+ )}\/packages\/(react-router-dom|react-router-website(-*)?)\/(.*)`
+ ),
+ new RegExp(
+ `^${escapeRegExp(
+ rootPackagePath
+ )}\/packages\/react-router-native\/node_modules\/react-router(.*)`
+ )
//new RegExp(`^${escapeRegExp(rootPackagePath)}\/packages\/react-router\/node_modules\/(.*)`),
];
@@ -17,13 +25,11 @@ config.getProjectRoots = () => getRoots();
config.getAssetRoots = () => getRoots();
function getRoots() {
- return [
- path.join(__dirname, '../../'),
- ];
+ return [path.join(__dirname, "../../")];
}
function escapeRegExp(s) {
- return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
+ return s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
}
module.exports = config;
diff --git a/packages/react-router-redux/modules/ConnectedRouter.js b/packages/react-router-redux/modules/ConnectedRouter.js
index 3020bcd21b..a525090d65 100644
--- a/packages/react-router-redux/modules/ConnectedRouter.js
+++ b/packages/react-router-redux/modules/ConnectedRouter.js
@@ -1,8 +1,8 @@
-import React, { Component } from 'react'
-import PropTypes from 'prop-types'
-import { Router } from 'react-router'
+import React, { Component } from "react";
+import PropTypes from "prop-types";
+import { Router } from "react-router";
-import { LOCATION_CHANGE } from './reducer'
+import { LOCATION_CHANGE } from "./reducer";
class ConnectedRouter extends Component {
static propTypes = {
@@ -10,36 +10,36 @@ class ConnectedRouter extends Component {
history: PropTypes.object.isRequired,
children: PropTypes.node,
isSSR: PropTypes.bool
- }
+ };
static contextTypes = {
store: PropTypes.object
- }
+ };
handleLocationChange = location => {
this.store.dispatch({
type: LOCATION_CHANGE,
payload: location
- })
- }
+ });
+ };
componentWillMount() {
- const { store:propsStore, history, isSSR } = this.props
- this.store = propsStore || this.context.store
+ const { store: propsStore, history, isSSR } = this.props;
+ this.store = propsStore || this.context.store;
if (!isSSR)
- this.unsubscribeFromHistory = history.listen(this.handleLocationChange)
+ this.unsubscribeFromHistory = history.listen(this.handleLocationChange);
- this.handleLocationChange(history.location)
+ this.handleLocationChange(history.location);
}
componentWillUnmount() {
- if (this.unsubscribeFromHistory) this.unsubscribeFromHistory()
+ if (this.unsubscribeFromHistory) this.unsubscribeFromHistory();
}
render() {
- return
+ return ;
}
}
-export default ConnectedRouter
+export default ConnectedRouter;
diff --git a/packages/react-router-redux/modules/__tests__/ConnectedRouter-test.js b/packages/react-router-redux/modules/__tests__/ConnectedRouter-test.js
index 4222f6cab6..5d3be90d30 100644
--- a/packages/react-router-redux/modules/__tests__/ConnectedRouter-test.js
+++ b/packages/react-router-redux/modules/__tests__/ConnectedRouter-test.js
@@ -1,28 +1,30 @@
-import React from 'react'
-import renderer from 'react-test-renderer'
-import {Switch, Route, Redirect} from 'react-router'
-import { applyMiddleware, createStore, combineReducers } from 'redux'
-import { Provider } from 'react-redux'
-import createHistory from 'history/createMemoryHistory'
+import React from "react";
+import renderer from "react-test-renderer";
+import { Switch, Route, Redirect } from "react-router";
+import { applyMiddleware, createStore, combineReducers } from "redux";
+import { Provider } from "react-redux";
+import createHistory from "history/createMemoryHistory";
-import ConnectedRouter from '../ConnectedRouter'
-import { LOCATION_CHANGE, routerReducer } from '../reducer'
-import routerMiddleware from '../middleware'
-import { push } from '../actions'
+import ConnectedRouter from "../ConnectedRouter";
+import { LOCATION_CHANGE, routerReducer } from "../reducer";
+import routerMiddleware from "../middleware";
+import { push } from "../actions";
-describe('A ', () => {
- let store, history
+describe("A ", () => {
+ let store, history;
beforeEach(() => {
- store = createStore(combineReducers({
- router: routerReducer
- }))
+ store = createStore(
+ combineReducers({
+ router: routerReducer
+ })
+ );
- history = createHistory()
- })
+ history = createHistory();
+ });
- it('connects to a store via Provider', () => {
- expect(store.getState()).toHaveProperty('router.location', null)
+ it("connects to a store via Provider", () => {
+ expect(store.getState()).toHaveProperty("router.location", null);
renderer.create(
@@ -30,61 +32,63 @@ describe('A ', () => {
Test
- )
+ );
- expect(store.getState()).toHaveProperty('router.location.pathname')
- })
+ expect(store.getState()).toHaveProperty("router.location.pathname");
+ });
- it('connects to a store via props', () => {
- expect(store.getState()).toHaveProperty('router.location', null)
+ it("connects to a store via props", () => {
+ expect(store.getState()).toHaveProperty("router.location", null);
renderer.create(
Test
- )
+ );
- expect(store.getState()).toHaveProperty('router.location.pathname')
- })
+ expect(store.getState()).toHaveProperty("router.location.pathname");
+ });
- it('updates the store with location changes', () => {
+ it("updates the store with location changes", () => {
renderer.create(
} />
)}
/>
-
- ), node)
-
- expect(node.innerHTML).toContain(TEXT)
- })
-
- it('continues to use parent\'s prop location after navigation', () => {
- const TEXT = 'cheddar pretzel'
- const node = document.createElement('div')
- let push
- ReactDOM.render((
-
+ ,
+ node
+ );
+
+ expect(node.innerHTML).toContain(TEXT);
+ });
+
+ it("continues to use parent's prop location after navigation", () => {
+ const TEXT = "cheddar pretzel";
+ const node = document.createElement("div");
+ let push;
+ ReactDOM.render(
+ {
- push = history.push
+ push = history.push;
return (
- (
-
{TEXT}
- )} />
- )
+
{TEXT}
}
+ />
+ );
}}
/>
-
- ), node)
- expect(node.innerHTML).toContain(TEXT)
- push('/chips')
- expect(node.innerHTML).toContain(TEXT)
- })
- })
-})
+ ,
+ node
+ );
+ expect(node.innerHTML).toContain(TEXT);
+ push("/chips");
+ expect(node.innerHTML).toContain(TEXT);
+ });
+ });
+});
diff --git a/packages/react-router/modules/__tests__/Router-test.js b/packages/react-router/modules/__tests__/Router-test.js
index 9b4a715f82..23ed306f2c 100644
--- a/packages/react-router/modules/__tests__/Router-test.js
+++ b/packages/react-router/modules/__tests__/Router-test.js
@@ -1,20 +1,20 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import PropTypes from 'prop-types'
-import Router from '../Router'
-import { createMemoryHistory as createHistory } from 'history'
+import React from "react";
+import ReactDOM from "react-dom";
+import PropTypes from "prop-types";
+import Router from "../Router";
+import { createMemoryHistory as createHistory } from "history";
-describe('A ', () => {
- const node = document.createElement('div')
+describe("A ", () => {
+ const node = document.createElement("div");
afterEach(() => {
- ReactDOM.unmountComponentAtNode(node)
- })
+ ReactDOM.unmountComponentAtNode(node);
+ });
+
+ describe("when it has more than one child", () => {
+ it("throws an error explaining a Router may have only one child", () => {
+ spyOn(console, "error");
- describe('when it has more than one child', () => {
- it('throws an error explaining a Router may have only one child', () => {
- spyOn(console, 'error')
-
expect(() => {
ReactDOM.render(
@@ -22,117 +22,114 @@ describe('A ', () => {
Bar
,
node
- )
- }).toThrow(/A may have only one child element/)
- })
- })
+ );
+ }).toThrow(/A may have only one child element/);
+ });
+ });
- describe('with exactly one child', () => {
- it('does not throw an error', () => {
+ describe("with exactly one child", () => {
+ it("does not throw an error", () => {
expect(() => {
ReactDOM.render(
} />
-
- ), node)
+ ,
+ node
+ );
- expect(node.innerHTML).toMatch(/one/)
- })
+ expect(node.innerHTML).toMatch(/one/);
+ });
- it('renders the first that matches the URL', () => {
- const node = document.createElement('div')
+ it("renders the first that matches the URL", () => {
+ const node = document.createElement("div");
- ReactDOM.render((
-
+ ReactDOM.render(
+
- (
-
one
- )}/>
-
-
- (
-
two
- )}/>
+
one
} />
+
+
+
two
} />
-
- ), node)
+ ,
+ node
+ );
- expect(node.innerHTML).toMatch(/two/)
- })
+ expect(node.innerHTML).toMatch(/two/);
+ });
- it('does not render a second or that also matches the URL', () => {
- const node = document.createElement('div')
+ it("does not render a second or that also matches the URL", () => {
+ const node = document.createElement("div");
- ReactDOM.render((
-
+ ReactDOM.render(
+
- (
-