1.this.$router.push()
描述:跳轉到指定的url,但這個方法回向history添加一個記錄,點擊后退會返回到上一個頁面。
用法:
// 1字符串
this.$router.push('/user/order')
// 2對象
this.$router.push({ path: '/user/order' })
//3傳參
this.$router.push({ path: '/user/order', query: {id: 123} })
//3-1取參數
this.$route.query.id
//4命名的路由
this.$router.push({ name: '/user/order', params: {id: 123} })
//4-1取參數
this.$route.params.id
2.this.$router.replace()
描述:同樣是跳轉到指定的url,但是這個方法不會向history里面添加新的記錄,點擊返回,會跳轉到上上一個頁面。上一個記錄是不存在的。
用法:同this.$router.push()
3.this.$router.go(n)
相對于當前頁面向前或向后跳轉n個頁面。n可為正數可為負數。