vue router.push(),router.replace(),router.go()和router.replace后需要返回两次的问题
转载:https://www.cnblogs.com/lwwen/p/7245083.html
https://blog.csdn.net/qq_15385627/article/details/83146766
1.router.push(location)=====window.history.pushState
想要导航到不同的 URL,则使用 router.push 方法。这个方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,则回到之前的 URL。
// 字符串
router.push('home') // 对象
router.push({ path: 'home' }) // 命名的路由
router.push({ name: 'user', params: { userId: 123 }}) // 带查询参数,变成 /register?plan=private
router.push({ path: 'register', query: { plan: 'private' }})
2.router.replace(location)=====window.history.replaceState
跟 router.push 很像,唯一的不同就是,它不会向 history 添加新记录,而是跟它的方法名一样 —— 替换掉当前的 history 记录
3.router.go(n)====window.history.go
// 在浏览器记录中前进一步,等同于 history.forward()
router.go(1) // 后退一步记录,等同于 history.back()
router.go(-1) // 前进 3 步记录
router.go(3) // 如果 history 记录不够用,那就默默地失败呗
router.go(-100)
router.go(100)
附:----------------------------
vue.router中replace需要返回两次问题及解决方案
- 问题:现有三个页面a , b , c , 递进关系,a页面router.push跳转至b,b再router.push跳转至c,c使用$router.replace()回到b,然后点击b页面的返回键,需要点击两次才能回到a页面
- 需求:c保持router.replace至b方式不变,b页面返回键点击一次正常返回a页面
- 解决方法:使用replace方法之后,再使用router.go(-1)方法返回一次就可以。
例:this.router.replacePage({name:'b'})
this.router.go(-1) - 原理:先解析一下几种页面跳转方式的不同,
- router.push : 跳转到新的页面,向history栈添加新一个新纪录,点击返回,返回到上一级页面。
- router.replace: 打开新的页面,不会像history添加新纪录,而是直接替换掉当前记录。
- router.go: 在history有记录的情况下,前进后退相应的页面。
页面的跳转记录就是:a->b->c->b
页面的堆栈记录则是:a->b->b
那么返回的时候路线就是b->b->a,相当于b页面有两个,但由于b页面是一模一样的,所以视觉上是觉得点了两次返回键。
那么解决的思路就很清晰了,减少history中的b的记录,就是在用b替换c页面记录同时,回退一页,记录就变成a->b,返回的时候自然是直接回到a。
vue router.push(),router.replace(),router.go()和router.replace后需要返回两次的问题的更多相关文章
- vue router.push(),router.replace(),router.go()
1.router.push(location)=====window.history.pushState 想要导航到不同的 URL,则使用 router.push 方法.这个方法会向 history ...
- router.go,router.push,router.replace的区别
除了使用 <router-link> 创建 a 标签来定义导航链接,我们还可以借助 router 的实例方法,通过编写代码来实现.当你点击 <router-link> 时,这个 ...
- Vue页面跳转$router.push 的用法
vue2.0在使用的过程中, .vue文件之间的跳转,在template中的常见写法是: <router-link to="/miniCard/statement/horizon&qu ...
- vue中this.$router.push()路由传值和获取的两种常见方法
1.路由传值 this.$router.push() (1) 路由跳转使用router.push()方法,这个方法会向history栈添加一个新纪录,所以,当用户点击浏览器后退按钮时,会回到之前的 ...
- vue 中router.go;router.push和router.replace的区别
vue 中router.go:router.push和router.replace的区别:https://blog.csdn.net/div_ma/article/details/79467165 t ...
- vue中router.go、router.push和router.replace的区别
router.go(n) 这个方法的参数是一个整数,意思是在history记录中向前或者后退多少,类似window.history.go(n) router.push(location) 想要导航到不 ...
- vue 中router.go、router.push和router.replace的区别
router.go(n) 这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n) router.push(location) 想要 ...
- Vue this.$router.push、replace、go的区别
1.this.$router.push 描述:跳转到不同的url,但这个方法会向history添加一个记录,点击后会返回到上一个页面 用法 //字符串 this.$router.push('home' ...
- vue 之this.$router.push、replace、go的区别
一.this.$router.push 说明:跳转到指定URL,向history栈添加一个新的记录,点击后退会返回至上一个页面 使用: this.$router.push('/index') this ...
随机推荐
- Excepting a "Mapping" node but got ... Ingnore "Except mapping" in project
问题 配置端口出现以下问题 问题原因: 解析失败 解决方式: 先将把application.yml 改为 application.properties, 再将端口号文件改为如下格式 解决
- 人人项目renren-security\git\renren-security的目录下的文件列表
\.git\config; \.git\FETCH_HEAD; \.git\HEAD; \.git\index; \.git\logs\HEAD; \.git\logs\refs\heads\mast ...
- Java-Servlet--《12-WEB应用中的普通Java程序如何读取资源文件.mp4》 有疑问
\第五天-servlet开发和ServletConfig与ServletContext对象\12-WEB应用中的普通Java程序如何读取资源文件.mp4; 多层时,DAO为了得到资源文件中的配置参数: ...
- flask基本介绍及虚拟环境
Flask Flask诞生于2010年,是Armin ronacher(人名)用 Python 语言基于 Werkzeug 工具箱编写的轻量级Web开发框架. Flask 本身相当于一个内核,其他几乎 ...
- 修改/dev/shm大小 tmps
/dev/shm 在oracle开启AMM时发现/dev/shm下的空间不够用 WARNING: You are trying to use the MEMORY_TARGET feature. T ...
- Spring @Bean注解 (基于java的容器注解)
基于java的容器注解,意思就是使用Java代码以及一些注解,就可以取代spring 的 xml配置文件. 1-@Configuration & @Bean的配合 @Configuration ...
- C# 如何进行图像的压缩
从网上找的非常有效.图片3M到500k private static ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCode ...
- 【ARTS】01_19_左耳听风-20190318~20190324
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- Python3-协程
协程 引子 协程介绍 Greenlet Gevent介绍 Gevent之应用举例 一 引子 本节的主题是基于单线程来实现并发,即只用一个主线程(很明显可利用的cpu只有一个)情况下实现并发,为此我们需 ...
- dubbo源码分析3——SPI机制中的ExtensionLoader类的objectFactory属性分析
ExtensionLoader类是整个SPI的核心类,每个SPI都会对应一个ExtensionLoader类实例,这个类的构造方法如下: private ExtensionLoader(Class&l ...