import { IndexRoute } from 'react-router';
import { isArray } from 'lodash/lang';
import { flattenDeep } from 'lodash/array';

/**
 * NOTE: We could likely use createRoutes to our advantage here. It may simplify
 * the code we currently use to recurse over the virtual dom tree:
 *
 * import { createRoutes } from 'react-router';
 * console.log(createRoutes(routes)); =>
 * [ { path: '/',
 *    component: [Function: Layout],
 *    childRoutes: [ [Object], [Object] ] } ]
 *
 * Ex:
 * const routes = (
 *   <Route component={App} path='/'>
 *     <Route component={About} path='/about' />
 *   </Route>
 * );
 *
 * getAllPaths(routes); => ['/', '/about]
 */
export const getNestedPaths = (route, prefix = '') => {
  if (!route) return [];

  if (isArray(route)) return route.map(x => getNestedPaths(x, prefix));

  // Index routes don't represent a distinct path, so we don't count them
  if (route.type === IndexRoute) return [];

  const path = prefix + route.props.path;
  const nextPrefix = path === '/' ? path : path + '/';
  return ([path].concat(getNestedPaths(route.props.children, nextPrefix)));
};

export const getAllPaths = routes => {
  return flattenDeep(getNestedPaths(routes));
};

export default getAllPaths;

@@ -1,47 +1,4 @@
-import %7B IndexRoute %7D from 'react-router';%0A
 impo
@@ -9,16 +9,29 @@
  isArray
+, isUndefined
  %7D from 
@@ -90,16 +90,242 @@
 rray';%0A%0A
+/**%0A * This is not a very sophisticated checking method. Assuming we already know%0A * this is either a Route or an IndexRoute under what cases would this break?%0A */%0Aconst isIndexRoute = route =%3E isUndefined(route.props.path);%0A%0A
 /**%0A * N
@@ -1086,23 +1086,10 @@
 if (
-route.type === 
+is
 Inde
@@ -1090,24 +1090,31 @@
 isIndexRoute
+(route)
 ) return %5B%5D;

Fix innacurate test for whether or not a route was an IndexRoute