路由的跳转有两种形式:
声明式导航router-link to="/login",务必要有to属性。
可以进行路由的跳转编程式导航push|replace,可以进行路由跳转
编程式导航:$router.push||replace
声明式导航能做的,编程式导航都能在, 但是编程式导航除了可以进行路由跳转,还可以做一些其他的业务逻辑。
<button class="sui-btn btn-xlarge btn-danger" type="button" @click="goSearch">搜索</button>
methods:{
// 搜索按钮的回调函数,需要向Search路由跳转
goSearch(){
this.$router.push("/search")
}
}
小知识:
我们可以根据组件身上的$route获取当前路由的信息,通过路由路径判断Footer显示与隐藏。
配置的路由的时候,可以给路由添加路由元信息【meta】,路由需要配置对象,
App.vue
v-show="$route.meta.show"
router/index,js
routes:[
{
path:'/home',
// 路径和哪个组件
component:Home,
meta:{show:true},
},
]