router.js 799 Bytes
import Vue from 'vue'
import Router from 'vue-router'
// import Login from '@/components/login'
// import Index from '@/components/index'
import index from '../components/index/layout'
Vue.use(Router)
const routes = [
  {
    //path: '',component: index,
    path: '*',
    name: 'index',
    component: index
  }
];
const router=new Router({ routes ,mode: 'history'});//hash(带#)值模式,vue-router 默认 hash 模式
//router.beforeEach((to, from, next) => {
//  if (to.matched.length ===0) {//如果未匹配到路由
//    from.name ? next({ name:from.name }) : next('/');//如果上级也未匹配到路由则跳转登录页面,如果上级能匹配到则转上级路由
//  } else {
//    next();//如果匹配到正确跳转
//  }
//});
//router.push(index);
export default router;