除了使用 <router-link> 创建 a 标签来定义导航链接,我们还可以借助 router 的实例方法,通过编写代码来实现。当你点击 <router-link> 时,这个方法会在内部调用,所以说,点击 <router-link :to="..."> 等同于调用 router.push(...)

声明式 编程式
<router-link :to="..."> router.push(...)

该方法的参数可以是一个字符串路径,或者一个描述地址的对象,例如:

// 字符串
router.push('home') // 对象
router.push({ path: 'home' }) // 命名的路由
router.push({ name: 'user', params: { userId: 123 }}) // 带查询参数,变成 /register?plan=private
router.push({ path: 'register', query: { plan: 'private' }}) const userId = 123
router.push({ name: 'user', params: { userId }}) // -> /user/123
router.push({ path: `/user/${userId}` }) // -> /user/123
// 这里的 params 不生效
router.push({ path: '/user', params: { userId }}) // -> /user

router.replace(location, onComplete?, onAbort?)

跟 router.push 很像,唯一的不同就是,它不会向 history 添加新记录,而是跟它的方法名一样 —— 替换掉当前的 history 记录。

声明式 编程式
<router-link :to="..." replace> router.replace(...)

router.go(n)

这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n)

例子:

// 在浏览器记录中前进一步,等同于 history.forward()
router.go(1) // 后退一步记录,等同于 history.back()
router.go(-1) // 前进 3 步记录
router.go(3) // 如果 history 记录不够用,那就默默地失败呗
router.go(-100)
router.go(100)

router.go,router.push,router.replace的区别的更多相关文章

  1. VUE的两种跳转push和replace对比区别

    router.push(location) 在vue.js中想要跳转到不同的 URL,需要使用 router.push 方法. 这个方法会向 history 栈添加一个新的记录,当用户点击浏览器后退按 ...

  2. [Vue]vue-router的push和replace的区别

    1.this.$router.push() 描述:跳转到不同的url,但这个方法会向history栈添加一个记录,点击后退会返回到上一个页面. 2.this.$router.replace() 描述: ...

  3. react中路由跳转push与replace的区别

    路由跳转,replace / push 区别 push: a-b-c 可以回到上一级 例: this.props.history.push('路由地址') replace: a-b-c 回不到上一级 ...

  4. React native路由跳转navigate、push、replace的区别

    由于没有系统的去学习RN,对路由跳转了解不多,只是跟着项目在做,抽点时间简单学习一下RN路由跳转方法区别,总结如下: 如上图,外部是一个栈容器,此时A页面在最底部,navigate到B页面,为什么此时 ...

  5. vue 中router.go;router.push和router.replace的区别

    vue 中router.go:router.push和router.replace的区别:https://blog.csdn.net/div_ma/article/details/79467165 t ...

  6. [Angular2 Router] Programmatic Router Navigation via the Router API - Relative And Absolute Router Navigation

    In this tutorial we are going to learn how to navigate programmatically (or imperatively) by using t ...

  7. window.location.href 和 window.location.replace 的区别

    window.location.href  和  window.location.replace 的区别 1.window.location.href=“url”:改变url地址: 2.window. ...

  8. Document.location.href和.replace的区别

    转自:https://www.cnblogs.com/GT_Andy/archive/2007/10/31/1922138.html 1 Document.location.href和.replace ...

  9. push和commit的区别

    push和commit的区别 git作为支持分布式版本管理的工具,它管理的库(repository)分为本地库.远程库.git commit操作的是本地库,git push操作的是远程库. git c ...

  10. push和pop的区别?

    1.push是什么?(推进) push就是推,延伸为推进.这个它是汇编的一个指令,(在其它语言中也可能会见到它).意思都是差不多的,就是把一个元素放入栈中.你可以假想栈是一个放光盘的那种盒子,有底没盖 ...

随机推荐

  1. Element-table-formatter格式化数据

    1.formatter  用来格式化内容   对table的值进行处理.Function(row, column, cellValue, index){}   使用formatter需要注意以下几点: ...

  2. MYSQL PROCEDURE 测试用例

    /** * 查询俱协信息 */ DROP PROCEDURE IF EXISTS `get_club_list`; DELIMITER $$ CREATE PROCEDURE `get_club_li ...

  3. abap特性

    1:实例成员是属于某一个对象的,静态成员属于整个类. 2:abap类中,可以定义三种不同类型的成员,分布是属性(如data),方法(method),事件(event). 3: abap中定义静态属性的 ...

  4. 全连接与softmax[转载]

    转自:https://www.jianshu.com/p/88bb976ccbd9 1.全连接示例: 2.softmax softmax输入层应和输出层(输出维度与类别数一致)纬度一样,如果不一样,就 ...

  5. Notes for Neural Network Methods for Natural Language Processing

    什么是深度学习?   一种机器学习算法,based on [多层][非线性变换]的[神经网络]结构 优点:可以使用 低维 稠密 连续 的向量表示不同粒度的语言单元, 还可以使用循环.卷积.递归等神经网 ...

  6. [LeetCode] 106. Construct Binary Tree from Postorder and Inorder Traversal_Medium tag: Tree Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  7. InterProScan 5.25-64.0 安装和使用

    InterProScan 5.25-64.0 安装和使用,目前最新版的interproscan 引用自 每日一生信--interproscan安装及使用(终结版)原文官网:http://code.go ...

  8. cocos2d-x JS 利用重复动作实现动画播放(实现倒计时)

    cocos2d-js: cc.delayTime() and cc.repeatForever() don't work together in cc.sequence() this.numm = 1 ...

  9. python字典对与list对象组合使用小问题

    遇到的低级错误,做个小记录,防止下次在陷进去........ 两行数据,分别每行做为一个字典,存传在list中,但是现在问题来了,第二行的数据会覆盖第一行.结果就是,list存储了的两个元素的数据一样 ...

  10. mysql group_concat用法

    MySQL中group_concat函数 完整的语法如下: group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔 ...