From f8af04ba4b20162d714501acdcf59dcb829f9f41 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Tue, 24 Jul 2018 14:37:31 +0100 Subject: [PATCH] prevent an error upon pressing the back button on the splash screen --- app/src/component/AppNavigator.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/component/AppNavigator.js b/app/src/component/AppNavigator.js index 91a4f0a1..18f3ef05 100644 --- a/app/src/component/AppNavigator.js +++ b/app/src/component/AppNavigator.js @@ -128,12 +128,14 @@ class AppWithNavigationState extends React.Component { const { dispatch, nav } = this.props; // There should be a better way to check this if (nav.routes.length > 0) { - const subRoutes = nav.routes[0].routes[0].routes; - const lastRoute = subRoutes[subRoutes.length - 1]; - if (nav.routes[0].routes[0].index > 0 && - ['About', 'Settings'].indexOf(lastRoute.key) > -1) { - dispatch(NavigationActions.back()); - return true; + if (nav.routes[0].routes && nav.routes[0].routes.length > 0) { + const subRoutes = nav.routes[0].routes[0].routes; + const lastRoute = subRoutes[subRoutes.length - 1]; + if (nav.routes[0].routes[0].index > 0 && + ['About', 'Settings'].indexOf(lastRoute.key) > -1) { + dispatch(NavigationActions.back()); + return true; + } } if (nav.routes[0].routeName === 'Main') { if (nav.routes[0].routes[0].routes[0].index > 0) {