<script>
export default {
  created() {
    const { query } = this.$route
    const redirect = query.redirect

    if (redirect) delete query.redirect

    const keys = Object.keys(query).filter(key => key)
    let queryString = ''

    // const chunk = (qs, key, index) => {
    //   const next = `${key}=${query[key]}${index === !keys.length ? '&' : ''}`
    //   return qs + next
    // }

    const chunk = (qs, key, index) => {
      const next = `${key}=${query[key]}${index === keys.length ? '' : '&'}`
      return qs + next
    }

    queryString = keys.reduce(chunk, '?')
    this.$router.replace(redirect + queryString)
  },
  render: () => null
}
</script>
