export default function ({ store, app, redirect }) {
  app.router.beforeEach((to, from, next) => {
    // if (to.path === '/') {
    //   redirect({ path: '/list', query: to.query })
    //   return
    // }
    const { uin = 0, id = 0, sessionId = 0 } = to.query

    if (!uin) {
      app.context.error({ statusCode: 404, message: 'This page could not be found' })
    }
    store.commit('users/SET_UIN', uin)

    if (['/list', '/index', '/message', '/winners'].includes(to.path) && !id) {
      app.context.error({ statusCode: 450, message: 'Incomplete route, parameter: ID not found' })
    }

    if (['/index', '/message'].includes(to.path) && !sessionId) {
      app.context.error({ statusCode: 450, message: 'Incomplete route, parameter: found：sessionId not found' })
    }

    next()
  })
}
