index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import BackgroundDevopsRouter from './background_devops'
  4. // 懒加载引入页面组件
  5. const Login = () => import('@/views/Login')
  6. const Background = () => import('@/views/admin/Background')
  7. const Dashboard = () => import('@/views/admin/Dashboard')
  8. const NotFound = () => import('@/views/404.vue')
  9. Vue.use(VueRouter)
  10. export const constantRoutes = [
  11. {
  12. path: '/login',
  13. name: 'Login',
  14. component: Login,
  15. meta: { title: '登录', needAuth: false }
  16. },
  17. {
  18. path: '/',
  19. redirect: '/bg', // 根路径直接引导至 /bg
  20. meta: { needAuth: true }
  21. },
  22. {
  23. path: '/bg',
  24. component: Background,
  25. meta: { needAuth: true },
  26. children: [
  27. {
  28. path: '', // 访问 /bg 时,默认渲染此组件
  29. name: 'DashboardIndex',
  30. component: Dashboard,
  31. // 注意:这里 title 设为“控制台”,方便 TagsView 显示
  32. meta: { title: '控制台', icon: 'el-icon-odometer', needAuth: true, roles: ['admin'] }
  33. },
  34. {
  35. path: 'dashboard', // 同时也保留 /bg/dashboard 的访问能力
  36. name: 'Dashboard',
  37. component: Dashboard,
  38. meta: { title: '控制台', icon: 'el-icon-odometer', needAuth: true, roles: ['admin'] }
  39. }
  40. ]
  41. }
  42. ]
  43. export const asyncRoutes = [
  44. BackgroundDevopsRouter,
  45. {
  46. path: '*',
  47. name: '404',
  48. component: NotFound,
  49. meta: { title: '404', needAuth: false }
  50. }
  51. ]
  52. const router = new VueRouter({
  53. mode: 'history',
  54. base: process.env.BASE_URL,
  55. routes: constantRoutes,
  56. scrollBehavior(to, from, savedPosition) {
  57. return { x: 0, y: 0 }
  58. }
  59. })
  60. export default router