From 2419309e046c854dedc3fca7519feab83a3369d7 Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Thu, 22 Mar 2018 22:41:27 -0400 Subject: [PATCH] Implement paths on SwitchRouter (#3806) * Fix paths overriding in SwitchRouter --- packages/react-navigation/src/routers/SwitchRouter.js | 6 ++++-- .../src/routers/__tests__/SwitchRouter-test.js | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/react-navigation/src/routers/SwitchRouter.js b/packages/react-navigation/src/routers/SwitchRouter.js index 310b5ed7..33c54999 100644 --- a/packages/react-navigation/src/routers/SwitchRouter.js +++ b/packages/react-navigation/src/routers/SwitchRouter.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) { diff --git a/packages/react-navigation/src/routers/__tests__/SwitchRouter-test.js b/packages/react-navigation/src/routers/__tests__/SwitchRouter-test.js index 9a3e26ff..04929465 100644 --- a/packages/react-navigation/src/routers/__tests__/SwitchRouter-test.js +++ b/packages/react-navigation/src/routers/__tests__/SwitchRouter-test.js @@ -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' });