import Vue        from 'vue'
import Router     from 'vue-router'
import menuModule from '../store/modules/menu'
import lazyLoader from '../store/modules/menu/lazyLoader'

Vue.use(Router)

const router =  new Router({
  mode: 'history',
  routes: [
    ...generateRoutesFromMenu(menuModule.state.items),
    {
      name: 'News Edit',
      path: '/news/edit/:nid',
      components: lazyLoader('News/Edit')
    },
    {
      name: 'Post Edit',
      path: '/post/edit/:pid',
      components: lazyLoader('Post/Edit')
    },
    {
      name: 'Login',
      path: '/login',
      components: lazyLoader('Login')
    },
    {
      name: 'Registe',
      path: '/registe',
      components: lazyLoader('Registe')
    },
    {
      name: 'User',
      path: '/user',
      components: lazyLoader('User')
    }
  ]
})

function generateRoutesFromMenu (menu = [], routes = []) {
  for (let i = 0, l = menu.length; i < l; i++) {
    let item = menu[i]
    if (item.path) {
      routes.push(item)
    }
  }
  return routes
}

export default router

@@ -805,16 +805,182 @@
    %7D%0A  %5D
+,%0A  scrollBehavior (to) %7B%0A    if (to.hash) %7B%0A      return %7B%0A        selector: to.hash%0A      %7D%0A    %7D else %7B%0A      return %7B%0A        x: 0,%0A        y: 0%0A      %7D%0A    %7D%0A  %7D
 %0A%7D)%0A%0Afun

reset scroll when router change