<commit_before>const TYPES = [
  'communities',
  'featured-users',
  'recent',
  'recommended',
  'trending',
]

const getComponents = (location, cb) => {
  cb(null, require('../../containers/discover/Discover').default)
}

const bindOnEnter = path => (nextState, replace) => {
  const type = nextState.params.type

  // redirect back to root path if type is unrecognized
  if (type && TYPES.indexOf(type) === -1) {
    replace({ state: nextState, pathname: path })
  }
}

const indexRoute = {
  getComponents,
}

const explore = {
  path: 'explore(/:type)',
  getComponents,
  onEnter: bindOnEnter('/explore'),
}

const discover = {
  path: 'discover(/:type)',
  getComponents,
  onEnter: bindOnEnter('/discover'),
}

export {
  indexRoute,
  getComponents,
  discover,
  explore,
}

export default [
  discover,
  explore,
]
<commit_msg>Add some extra redirect logic for root path<commit_after>const TYPES = [
  'communities',
  'featured-users',
  'recent',
  'recommended',
  'trending',
]

const getComponents = (location, cb) => {
  cb(null, require('../../containers/discover/Discover').default)
}

const bindOnEnter = path => (nextState, replace) => {
  const type = nextState.params.type

  // redirect back to root path if type is unrecognized
  if (type && TYPES.indexOf(type) === -1) {
    replace({ state: nextState, pathname: path })
  }
}

const indexRoute = {
  getComponents,
}

const explore = {
  path: 'explore(/:type)',
  getComponents,
  onEnter: bindOnEnter('/explore'),
}

const exploreRoot = store => ({
  path: '/explore',
  getComponents,
  onEnter: (nextState, replace) => {
    const { params: { type } } = nextState
    const { authentication } = store.getState()

    const rootPath = authentication.isLoggedIn ? '/discover' : '/'

    if (type && TYPES.indexOf(type) === -1) {
      replace({ state: nextState, pathname: rootPath })
    } else if (authentication.isLoggedIn) {
      replace({ state: nextState, pathname: '/discover' })
    } else {
      replace({ state: nextState, pathname: '/' })
    }
  },
})

const discover = {
  path: 'discover(/:type)',
  getComponents,
  onEnter: bindOnEnter('/discover'),
}

export {
  indexRoute,
  getComponents,
  discover,
  explore,
  exploreRoot,
}

export default [
  discover,
  explore,
]
{'fraction_non_alphanumeric': 0.15743183817062445, 'fraction_numerical': 0.0013192612137203166, 'mean_word_length': 3.55, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2107550', 'n_tokens_mistral': 767, 'n_tokens_neox': 766, 'n_words': 180}