import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) const _import = require('./import-' + process.env.NODE_ENV) const routes = [ // { // path: '*', // redirect: '/404' // }, { path: '/404', name: '404', component: _import('page/404/index') }, { path: '/', name: 'index', component: _import('views/index/index') } ] const router = new VueRouter({ mode: 'history', routes, scrollBehavior (to, from, savedPosition) { if (to.hash) { return { selector: to.hash } } // keep-alive 返回缓存页面后记录浏览位置 if (savedPosition && to.meta.keepAlive) { return savedPosition } // 异步滚动操作 return new Promise((resolve) => { setTimeout(() => { resolve({ x: 0, y: 1 }) }, 0) }) } }) export default router