|
@@ -1,47 +1,63 @@
|
|
|
-import {createRouter,createWebHistory,createWebHashHistory} from 'vue-router';
|
|
|
+import {
|
|
|
+ createRouter,
|
|
|
+ createWebHistory,
|
|
|
+ createWebHashHistory,
|
|
|
+} from "vue-router";
|
|
|
|
|
|
// 路由:hash / history
|
|
|
// 2.页面的引入
|
|
|
-import Home from '@/pages/Home.vue';
|
|
|
-import List from '@/pages/List.vue';
|
|
|
-import My from '@/pages/My.vue';
|
|
|
-import Detail from '@/pages/Detail.vue';
|
|
|
+import Home from "../views/Home.vue";
|
|
|
+import List from "../views/List.vue";
|
|
|
+import My from "../views/My.vue";
|
|
|
+import Detail from "../views/Detail.vue";
|
|
|
// 1.创建
|
|
|
const router = createRouter({
|
|
|
- // 路由是什么版本
|
|
|
- history:createWebHistory(),
|
|
|
- // 路由的格式
|
|
|
- routes:[
|
|
|
- // 路由重定向
|
|
|
+ // 路由是什么版本
|
|
|
+ history: createWebHistory(),
|
|
|
+ // 路由的格式
|
|
|
+ routes: [
|
|
|
+ // 路由重定向
|
|
|
+ {
|
|
|
+ path: "/",
|
|
|
+ redirect: "/home",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ // 路由的路径
|
|
|
+ path: "/home",
|
|
|
+ // 这个页面用的元素
|
|
|
+ component: Home,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ path: "/list",
|
|
|
+ component: List,
|
|
|
+ children: [
|
|
|
{
|
|
|
- path:'/',
|
|
|
- redirect:'/home'
|
|
|
+ // 二级或多级 子路由 没有/
|
|
|
+ // path: "detail/:id/:user",
|
|
|
+ path:'/detail',
|
|
|
+ component: Detail,
|
|
|
+ name: "xiangqing",
|
|
|
+ // 1.全部接收
|
|
|
+ // props:true,
|
|
|
+ // 2.切换接收方法(默认是params)
|
|
|
+ // props(route) {
|
|
|
+ // return route.query
|
|
|
+ // }
|
|
|
+ // 3.默认传参
|
|
|
+ props:{
|
|
|
+ user:"我的",
|
|
|
+ id:"0976"
|
|
|
+ }
|
|
|
},
|
|
|
- {
|
|
|
- // 路由的路径
|
|
|
- path:'/home',
|
|
|
- // 这个页面用的元素
|
|
|
- component:Home
|
|
|
- },
|
|
|
- {
|
|
|
- path:'/list',
|
|
|
- component:List,
|
|
|
- children:[
|
|
|
- {
|
|
|
- // 二级或多级 子路由 没有/
|
|
|
- path:'detail/:id/:user',
|
|
|
- component:Detail,
|
|
|
- name:'xiangqing'
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- path:'/my',
|
|
|
- component:My,
|
|
|
- name:'wode'
|
|
|
- }
|
|
|
- ]
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ path: "/my",
|
|
|
+ component: My,
|
|
|
+ name: "wode",
|
|
|
+ },
|
|
|
+ ],
|
|
|
});
|
|
|
|
|
|
// 抛出
|
|
|
-export default router;
|
|
|
+export default router;
|