import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import Hero from './views/Hero.vue'
import Mint from './views/Mint.vue'
import Market from './views/Market.vue'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    },
    {
      path: '/hero',
      name: 'Hero',
      component: Hero
    },
    {
      path: '/mint',
      name: 'Mint',
      component: Mint
    },
    {
      path: '/market',
      name: 'Market',
      component: Market
    },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (about.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
    // }
  ]
})
//路由拦截
// let noLogin = ['/market', '/catdetail']
router.beforeEach((to, from, next) => {
  // 分发  触发事件
  // Vue.prototype.$eventHub.$emit('tabnav', to)
  // chrome
  document.querySelector("#app").scrollTop = 0
  // firefox
  document.documentElement.scrollTop = 0
  next()
  // if (noLogin.indexOf(to.path) <= -1) {
  // 	console.log(noLogin.indexOf(to.path))
  // 	clearLocalStrorage()
  // 	clearSessionStrorage()
  // 	next({
  // 		path: '/'
  // 	})
  // } else next()
})

const routerPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}

export default router
