import { createRouter, createWebHistory } from 'vue-router'
/* Layout */
import Layout from '@/layout'
// 公共路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login.vue'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        name: 'Index',
        component: () => import('@/views/screen/index.vue'),
        meta: { title: '首页', icon: 'home', affix: true }
      },
      {
        path: '/history_:timeFrame',
        name: 'history',
        component: () => import('@/views/history/index.vue'),
        meta: { title: '首页', icon: 'home', affix: true }
      },
    ]
  }
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  
  {
    path: '/',
    component: Layout,
    redirect: '/login',
    children: [
    ]
  },
  
]


const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
});

dynamicRoutes.forEach(route => { router.addRoute(route) })
export default router
