import router from '../router/index.js'
import store from '@/store'


const routeList = ['/Home',]
router.beforeEach((to, from, next) => {
  let userToken = window.localStorage.getItem('userToken')
  if (userToken) {
    let active = routeList.findIndex((item) => item === to.path)
    if (active > -1) {
      active++
    }
    store.commit('user/setNavActive', active)
    next()
  } else {
    if (to.path == '/login'||to.path == '/register'||to.path == '/forget-password') {
      next()
    } else {
      next('/login')
    }
  }
})
