获取当前页面路由

  • 完整url可以用 window.location.href
  • 路由路径可以用 this.$route.path
  • 路由路径参数 this.$route.params

判断当前路由不匹配时跳转

if(this.$route.path!='/Home'){
    this.$router.push({
        path:'/Home',
    })
}

vue $router和$route的区别

route相当于当前正在跳转的路由对象 可以从里面获取name,path,params,query等

打印this.$route和this.$router

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐