想要导航到不同的 URL,用 router.push 方法,会向 history 栈添加一个新的记录

<router-link> 《==》router.push

// 字符串
router.push('home')

// 命名的路由
router.push({ name: 'user', params: { userId: 123 }})

// 对象
router.push({ path: 'home' })

// 带查询参数,变成 /register?plan=private
router.push({ path: 'register', query: { plan: 'private' }})
//如果提供了 path,params 会被忽略,需完整设置路径:
const userId = 123;
router.push({ name: 'user', params: { userId }}) // -> /user/123
router.push({ path: `/user/${userId}` }) // -> /user/123
//在 router.push 或 router.replace 中提供 onComplete 和 onAbort 回调作为第二个和第三个参数

router.push(location, onComplete?, onAbort?)//导航成功完成或中止时
router.replace(location, onComplete?, onAbort?)

//replace它不会向 history 添加新记录
<router-link :to="..." replace>==》
router.replace(...)
router.go(n)
// 在浏览器记录中前进一步,等同于 history.forward()
router.go(1)

// 后退一步记录,等同于 history.back()
router.go(-1)

// 前进 3 步记录
router.go(3)

// 如果 history 记录不够用,那就默默地失败呗
router.go(-100)
router.go(100)

 

 posted on 2017-10-10 11:12  不了无明  阅读(341)  评论(0编辑  收藏  举报