index.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // 从路由库中导出创建方法
  2. import {createRouter,createWebHistory,createWebHashHistory} from 'vue-router';
  3. // 引入页面
  4. import Home from '../views/Home.vue';
  5. import My from '../views/My.vue';
  6. import List from '../views/List.vue';
  7. import Detail from '@/views/Detail.vue';
  8. import Hi from '@/components/Hi.vue';
  9. import Demo2 from '@/components/Demo2.vue';
  10. const router = createRouter({
  11. // 模式
  12. history: createWebHistory(),
  13. routes: [
  14. {
  15. path: '/',
  16. redirect:'/home'
  17. },
  18. {
  19. path:'/home',
  20. component: Home
  21. },
  22. {
  23. // path:'/detail/:id/:name',
  24. path:'/detail',
  25. component: Detail,
  26. name:'xiangqing'
  27. },
  28. {
  29. path:'/list',
  30. component: List,
  31. children:[
  32. {
  33. path:'',
  34. redirect:"/list/demo1"
  35. },
  36. {
  37. path:'demo1',
  38. component: Hi,
  39. // name:'nanzhuang'
  40. },
  41. {
  42. path:'demo3',
  43. component: ()=>import('../components/Demo3.vue'),
  44. // name:'nanzhuang'
  45. },
  46. {
  47. path:'demo2',
  48. // path:'demo2/:id/:name1',
  49. component: Demo2,
  50. // name:"nvzhuang"
  51. }
  52. ]
  53. },
  54. {
  55. path:'/my',
  56. component: My,
  57. name:"wode"
  58. },
  59. ]
  60. });
  61. export default router;