import Vue from 'vue'
import Router from 'vue-router'
import {menuRouter, otherRouter} from './routes.js'
Vue.use(Router)

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

function line(datas) {
  let lines = [];
  let routes = datas;
  for (let route of routes) {
    _line(route, lines);
  }
  return lines;
}

function _line(route, lines) {
  if (route.children && route.children.length > 0) {
    for (let child of route.children) {
      child.path = child.path;
      _line(child, lines);
    }
  } else {
    lines.push(route);
  }
}

let routesData = line(menuRouter).concat(line(otherRouter));

export default new Router({
  routes: routesData
})