1、Route(路由):当前激活的路由,包含当前路由的路径,查询参数,路由参数,元信息等。route只读,一般通过$route获取当前路由信息,
//URL: http://example.com?orderInfo=12345
let detailInfo = this.$route.query.orderInfo
//其中,this.$route表示当前路由信息;this.$route.query表示当前路由查询参数;this.$route.query.orderInfo,表示为oederInfo的查询参数,返回字符串‘12345’
let detailInfo = this.$route.path
//this.$route.path表示当前路由路径
2、Router(路由器):router是一个路由实例,负责管理和控制整个应用程序的路由。router一般用于导航路由,监听路由变化,提供路由守卫等功能。
let detailInfo = this.$router.push('/home')
//其中,this.$router是访问router实例
路由导航:
//1、push:直接在旧路径上添加新的路径信息
// 字符串路径
this.$router.push('/home')
// 对象描述地址
this.$router.push({ path: '/home' })
//2、replace:直接替换当前路由
// 字符串路径
this.$router.replace('/home')
// 对象描述地址
this.$router.replace({ path: '/home' })
//3、go+back:路由前进和路由回退
this.$router.go(2) //=this.$router.forward(2)
this.$router.back(2)