当前位置:网站首页>router.push(),router.repalce(),router.go()使用
router.push(),router.repalce(),router.go()使用
2022-07-26 10:38:00 【songywaa】
router对象提供了三个用于跳转链接的方法:
router.push( ... )=>跳转到某个子页面,并在history中添加一条记录router.repalce( ... )=>替换当前的页面,其实也可以理解为跳转,和push的区别就是不会在history中添加记录router.go(number)=>刚才提到的history,在go()中被使用,跳转到上一页就go(-1),跳转到下一页就go(1),当然实现跳转的前提都是history中有记录。
router. p u s h \color{red}{push} push(location, onComplete?, onAbort?)
| 声明式 | 编程式 |
|---|---|
| < router-link :to="…"> | router.push(…) |
// 方式一:字符串路径
router.push('/user')
// 方式二:path对象
router.push({
path: '/user' })
// 方式三:路由名称
router.push({
name: 'user'})
注 意 : 如 果 提 供 了 p a t h , p a r a m s 会 被 忽 略 , q u e r y 不 会 ! ! \color{green}{注意:如果提供了 path,params 会被忽略,query不会!!} 注意:如果提供了path,params会被忽略,query不会!!
// 不生效
router.push({
path: '/user', params: {
id: 1 }})
// params生效 /user/1
router.push({
name: 'user', params: {
id: 1 }}) // 使用name方式
router.push({
path: `/user/1` }) // 直接在path上扩充
// query不受影响 /user?id=1
router.push({
path: '/user', query: {
id: 1 }})
router. r e p l a c e \color{red}{replace} replace(location, onComplete?, onAbort?)
| 声明式 | 编程式 |
|---|---|
| < router-link :to="…" replace> | router.replace(…) |
跟 r o u t e r . p u s h 很 像 , 唯 一 的 不 同 就 是 , 它 不 会 向 h i s t o r y 添 加 新 记 录 ! \color{green}{跟router.push 很像,唯一的不同就是,它不会向 history 添加新记录!} 跟router.push很像,唯一的不同就是,它不会向history添加新记录!
router. g o \color{red}{go} 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)
边栏推荐
- 剑指Offer(五十二):正则化表达式
- uniapp使用简单方法signalR(仅用于web调试,无法打包app)
- 第8期:云原生—— 大学生职场小白该如何学
- 10 令 operator= 返回一个 reference to *this
- 剑指Offer(八):跳台阶
- The problem of large fluctuation of hx711 data
- .net operation redis sorted set ordered set
- 11 在 operator= 中处理“自我赋值”
- Okaleido生态核心权益OKA,尽在聚变Mining模式
- .net5wtm (asp.net core) PgSQL unpacking operation
猜你喜欢

Uniapp uses the simple method signalr (only for web debugging, cannot package apps)

Phase 4: one of College Students' vocational skills preparation in advance

.net5wtm (asp.net core) PgSQL unpacking operation

.NET5WTM(ASP.NET Core) PGSql开箱操作

在神州IV开发板上成功移植STemWin V5.22

Navicat15 MySQL (centos7) connected to local virtual machine

Issue 6: which mainstream programming language should college students choose

Problems encountered in QRcode QR code (C language)

数据分析入门 | kaggle泰坦尼克任务
![[leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字](/img/9b/624416fa6a408bf64ca5438273176b.png)
[leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字
随机推荐
[leetcode每日一题2021/4/29]403. 青蛙过河
centos8(liunx)部署WTM(ASP.NET 5)使用pgsql
What if MySQL can't get in
分布式锁解决方案之Redis实现
STM32 阿里云MQTT esp8266 AT命令
Issue 7: how do you choose between curling up and lying flat
【dectectron2】跟着官方demo一起做
Analysis of the transaction problem of chained method call
【机器学习小记】【人脸识别】deeplearning.ai course4 4th week programming
[leetcode每日一题2021/8/31]1109. 航班预订统计【中等】差分数组
Zongzi battle - guess who can win
uniapp使用简单方法signalR(仅用于web调试,无法打包app)
Introduction to Phoenix (Level 1: Phoenix installation, level 2: Phoenix basic grammar)
构造器、方法重载、对象数组和static
剑指Offer(五):用两个栈实现队列
数据分析入门 | kaggle泰坦尼克任务
2021-08-13和鹏哥学C语言-数组
sigmod 函数与softmax 函数对比
SuperMap IClient for Leaflet 加载高斯克吕格投影三度分带CGCS2000大地坐标系WMTS服务
剑指Offer(二十):包含min函数的栈