一、后台系统路由实现分析

1、入口文件中调用路由

src/main.js

  1. ......
  2. import router from './router' //引入路由模块
  3. ......
  4. new Vue({
  5. el: '#app',
  6. router, //挂载路由
  7. store,
  8. render: h => h(App)
  9. })

2、路由模块中定义路由

src/router/index.js

  1. ......
  2. export const constantRouterMap = [
  3. ......
  4. ]
  5. export default new Router({
  6. ......
  7. routes: constantRouterMap
  8. })

二、谷粒学院路由定义

1、复制icon图标

将vue-element-admin/src/icons/svg 中的图标复制到 guli-admin项目中

2、修改路由

修改 src/router/index.js 文件,重新定义constantRouterMap
注意:每个路由的name不能相同

  1. export const constantRouterMap = [
  2. { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  3. { path: '/404', component: () => import('@/views/404'), hidden: true },
  4. // 首页
  5. {
  6. path: '/',
  7. component: Layout,
  8. redirect: '/dashboard',
  9. name: 'Dashboard',
  10. children: [{
  11. path: 'dashboard',
  12. component: () => import('@/views/dashboard/index'),
  13. meta: { title: '谷粒学院后台首页', icon: 'dashboard' }
  14. }]
  15. },
  16. // 讲师管理
  17. {
  18. path: '/edu/teacher',
  19. component: Layout,
  20. redirect: '/edu/teacher/list',
  21. name: 'Teacher',
  22. meta: { title: '讲师管理', icon: 'peoples' },
  23. children: [
  24. {
  25. path: 'list',
  26. name: 'EduTeacherList',
  27. component: () => import('@/views/edu/teacher/list'),
  28. meta: { title: '讲师列表' }
  29. },
  30. {
  31. path: 'create',
  32. name: 'EduTeacherCreate',
  33. component: () => import('@/views/edu/teacher/form'),
  34. meta: { title: '添加讲师' }
  35. },
  36. {
  37. path: 'edit/:id',
  38. name: 'EduTeacherEdit',
  39. component: () => import('@/views/edu/teacher/form'),
  40. meta: { title: '编辑讲师', noCache: true },
  41. hidden: true
  42. }
  43. ]
  44. },
  45. { path: '*', redirect: '/404', hidden: true }
  46. ]

3、创建vue组件

在src/views文件夹下创建以下文件夹和文件
105c6a93-efd3-4e7b-937a-d46c202b7084.png

4、form.vue

  1. <template>
  2. <div class="app-container">
  3. 讲师表单
  4. </div>
  5. </template>

5、list.vue

  1. <template>
  2. <div class="app-container">
  3. 讲师列表
  4. </div>
  5. </template>