index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import HomeView from '../views/HomeView.vue'
  4. Vue.use(VueRouter)
  5. const routes = [
  6. {
  7. path: '/',
  8. name: 'home',
  9. component: HomeView
  10. },
  11. {
  12. path: '/about',
  13. name: 'about',
  14. // route level code-splitting
  15. // this generates a separate chunk (about.[hash].js) for this route
  16. // which is lazy-loaded when the route is visited.
  17. component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  18. },
  19. {
  20. // path 代表路由的路径 会显示在地址栏中
  21. path:"/mypage",
  22. // name 代表路由的名称
  23. name:"mypage",
  24. // component 代表路由的组件 当前要显示的页面
  25. component:() => import("../views/MyPage.vue"),
  26. // alias 别名
  27. alias:'/my',
  28. // children 代表子路由
  29. children:[
  30. {
  31. path:'/mypage/childone',
  32. name:'childone',
  33. component:() => import("../views/ChildOne.vue")
  34. },
  35. {
  36. path:'/mypage/childtwo',
  37. name:"childtwo",
  38. component:() => import("../views/ChildTwo.vue")
  39. },
  40. {
  41. path:'/mypage/childthree/:username/:age',
  42. name:'childthree',
  43. component:() => import("../views/ChildThree.vue")
  44. }
  45. ]
  46. },{
  47. path:'/backhome',
  48. redirect:'/'
  49. },{
  50. path:"/gochildthree/:username/:age",
  51. redirect:"/mypage/childthree/:username/:age"
  52. }
  53. ]
  54. const router = new VueRouter({
  55. routes
  56. })
  57. export default router