//该文件专门用于创建整个应用的路由器
import VueRouter from "vue-router";
//引入组件
import About from "@/pages/About";
import Home from "@/pages/Home";
import HomeNews from "@/pages/HomeNews";
import HomeMessage from "@/pages/HomeMessage";
import Detail from "@/pages/Detail";//创建并暴露一个路由器
export default new VueRouter({routes:[{path:'/about',component:About},{path:'/home',component:Home,children:[{path:'news',component:HomeNews},{path:'message',component:HomeMessage,children:[{path:'detail',component:Detail}]}]}]
})
消息编号:{{ $route.query.id }}消息标题:{{$route.query.title}}
- {m.title}}-->
{{m.title}}
{{m.title}}
{{m.title}}
$route.query.id
$route.query.title
//该文件专门用于创建整个应用的路由器
import VueRouter from "vue-router";
//引入组件
import About from "@/pages/About";
import Home from "@/pages/Home";
import HomeNews from "@/pages/HomeNews";
import HomeMessage from "@/pages/HomeMessage";
import Detail from "@/pages/Detail";//创建并暴露一个路由器
export default new VueRouter({routes:[{name:'guanyu',path:'/about',component:About},{path:'/home',component:Home,children:[{path:'news',component:HomeNews},{path:'message',component:HomeMessage,children:[{name:'xiangqing',path:'detail',component:Detail}]}]}]
})
-
{m.title}}-->
{{m.title}}
About Home
routes:[{path:'/demo',component:Demo,children:[{path:'test',component:Test,children:[{name:'hello', //给路由命名path:'welcome',component:Hello}]}]}]
(2)简化跳转
跳转
跳转
跳转
//该文件专门用于创建整个应用的路由器
import VueRouter from "vue-router";
//引入组件
import About from "@/pages/About";
import Home from "@/pages/Home";
import HomeNews from "@/pages/HomeNews";
import HomeMessage from "@/pages/HomeMessage";
import Detail from "@/pages/Detail";//创建并暴露一个路由器
export default new VueRouter({routes:[{name:'guanyu',path:'/about',component:About},{path:'/home',component:Home,children:[{path:'news',component:HomeNews},{path:'message',component:HomeMessage,children:[{name:'xiangqing',path:'detail/:id/:title', //nodejs的占位符,后面会填充内容component:Detail}]}]}]
})
-
{m.title}}-->
{{m.title}}
消息编号:{{ $route.params.id }}消息标题:{{$route.params.title}}
{path:'/home',component:Home,children:[{path:'news',component:HomeNews},{path:'message',component:HomeMessage,children:[{name:'xiangqing',path:'detail/:id/:title', //nodejs的占位符,后面会填充内容(使用占位符声明接收params参数)component:Detail}]}]
}
跳转 跳转
特别注意:路由携带params参数时,若使用to的对象写法,则不能使用path配置项,必使用name配置!
$route.params.id
$route.params.title