mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 22:39:41 +08:00
Fixes bug where null doesn't work in routerOptions paths object for deeplinking (#4791)
* Add test for handling null path set on router * Allow null paths on the router config Previously if you specified `null` in the router `paths`, the logic would actually fall back to the `path` specified on the route, which is especially bad if the latter is undefined, because then the path would be set as the default of the routeName.
This commit is contained in:
committed by
Eric Vicenti
parent
9d77fd6d54
commit
a94f89ffe1
@@ -547,6 +547,24 @@ const performRouterTest = createTestRouter => {
|
||||
expect(action.type).toEqual(NavigationActions.NAVIGATE);
|
||||
expect(action.routeName).toEqual('baz');
|
||||
});
|
||||
|
||||
test('paths option set as null on router overrides path from route config', () => {
|
||||
const router = createTestRouter(
|
||||
{
|
||||
main: {
|
||||
screen: MainNavigator,
|
||||
},
|
||||
baz: {
|
||||
path: 'bazPath',
|
||||
screen: FooNavigator,
|
||||
},
|
||||
},
|
||||
{ paths: { baz: null } }
|
||||
);
|
||||
const action = router.getActionForPathAndParams('b/noBaz', {});
|
||||
expect(action.type).toEqual(NavigationActions.NAVIGATE);
|
||||
expect(action.routeName).toEqual('baz');
|
||||
});
|
||||
};
|
||||
|
||||
describe('Path handling for stack router', () => {
|
||||
|
||||
@@ -74,7 +74,14 @@ export const createPathParser = (
|
||||
|
||||
// Build pathsByRouteNames, which includes a regex to match paths for each route. Keep in mind, the regex will pass for the route and all child routes. The code that uses pathsByRouteNames will need to also verify that the child router produces an action, in the case of isPathMatchable false (a null path).
|
||||
Object.keys(childRouters).forEach(routeName => {
|
||||
let pathPattern = pathConfigs[routeName] || routeConfigs[routeName].path;
|
||||
let pathPattern;
|
||||
|
||||
// First check for paths on the router, then check the route config
|
||||
if (pathConfigs[routeName] !== undefined) {
|
||||
pathPattern = pathConfigs[routeName];
|
||||
} else {
|
||||
pathPattern = routeConfigs[routeName].path;
|
||||
}
|
||||
|
||||
if (pathPattern === undefined) {
|
||||
// If the user hasn't specified a path at all, then we assume the routeName is an appropriate path
|
||||
|
||||
Reference in New Issue
Block a user