详解vue 路由跳转四种方式 (带参数)

如题所述

第1个回答  2022-07-17

this.$router.go(n)

向前或者向后跳转n个页面,n可为正整数或负整数

ps : 区别

this.$router.push

跳转到指定url路径,并想history栈中添加一个记录,点击后退会返回到上一个页面

this.$router.replace

跳转到指定url路径,但是history栈中不会有记录,点击返回会跳转到上上个页面 (就是直接替换了当前页面)

this.$router.go(n)

向前或者向后跳转n个页面,n可为正整数或负整数

完整url可以用 window.location.href
路由路径可以用 this.$route.path
路由路径参数 this.$route.params 例如:/user/:id → /user/2044011030 → this.$route.params.id
路由查询参数 this.$route.query 例如:/user/search?name=sf → this.$route.query.name

参考: https://www.cnblogs.com/bydzhangxiaowei/p/12000458.html
https://blog.csdn.net/a350110085/article/details/90053111

相似回答