1,动态路由匹配
const User = {
template: '<div>User</div>'
}
const router = new VueRouter({
routes: [
// 动态路径参数 以冒号开头
{ path: '/user/:id', component: User }
]
})
一个“路径参数”使用冒号 :标记。当匹配到一个路由时,参数值会被设置到 this.$route.params
,可以在每个组件内使用。
2,捕获所有路由或 404 Not found 路由
当使用通配符路由时,请确保路由的顺序是正确的,也就是说含有通配符的路由应该放在最后。路由 { path: '*' }
通常用于客户端 404 错误,也就是访问的路径错了明明是#/mine 确写成了#/mine111
3,嵌套路由也就是二级路由使用children
配置,children里面的路径不能写/
4,编程式的导航
1, this.$router.push("/dedail/" + id);
,路由的配置"/detail/:id" 接受的话 this.$route.params.id
2,this.$router.push({
path:"/dedail",
query:{
id
}
})
如果用path 和query 跳转页面带参数 路由的配置 “/detail” 接收的话 this.$route.query.id