Permalink
Browse files

Implement paths on SwitchRouter (#3806)

* Fix paths overriding in SwitchRouter
  • Loading branch information...
ericvicenti authored and brentvatne committed Mar 23, 2018
1 parent ee1b597 commit 5e4512f3ebef587bf90e4ec4d660708b72a0a865
Showing with 11 additions and 2 deletions.
  1. +4 −2 src/routers/SwitchRouter.js
  2. +7 −0 src/routers/__tests__/SwitchRouter-test.js
@@ -29,8 +29,10 @@ export default (routeConfigs, config = {}) => {
const childRouters = {};
order.forEach(routeName => {
const routeConfig = routeConfigs[routeName];
paths[routeName] =
typeof routeConfig.path === 'string' ? routeConfig.path : routeName;
if (!paths[routeName]) {
paths[routeName] =
typeof routeConfig.path === 'string' ? routeConfig.path : routeName;
}
childRouters[routeName] = null;
const screen = getScreenForRouteName(routeConfigs, routeName);
if (screen.router) {
@@ -78,6 +78,13 @@ describe('SwitchRouter', () => {
expect(state3.index).toEqual(0);
});
test('paths option on SwitchRouter overrides path from route config', () => {
const router = getExampleRouter({ paths: { A: 'overridden' } });
const action = router.getActionForPathAndParams('overridden', {});
expect(action.type).toEqual(NavigationActions.NAVIGATE);
expect(action.routeName).toEqual('A');
});
test('provides correct action for getActionForPathAndParams', () => {
const router = getExampleRouter({ backBehavior: 'initialRoute' });
const action = router.getActionForPathAndParams('A1', { foo: 'bar' });

0 comments on commit 5e4512f

Please sign in to comment.