关于vue路由跳转的问题

项目里面有个支付功能,支付成功之后直接会有一个带参数的回调地址返回,如下
http://localhost:8080/?flag=0&orderId=eqewrask3408lasj#/payreturn

现在发现的问题是如果在这个页面往别的地址里跳,参数会一直带在路由里,比如跳转到首页,地址是
http://localhost:8080/?flag=0&orderId=eqewrask3408lasj#/index,请教下如何再跳转时候把里边的参数?flag=0&orderId=eqewrask3408lasj去除呢,直接跳到http://localhost:8080/#/index

阅读 3k
6 个回答

你可以把参数放在hash路由后面

这个陷入到了「路径」的问题上了,用 router 的 params 和 query 都处理不了,只能自己做字符串处理。用正则删除参数就好。

`
const str = 'http://localhost:8080/?flag=0&orderId=eqewrask3408lasj#/index'
const reg = /\/\?.*#\//

const res = str.replace(reg, '/#/')
console.log(res) // http://localhost:8080/#/index
`

this.$router.push({ name: 'xxx', query: { flag: 0, orderId: 'eqewrask3408lasj' }}) 你试试用routerpush方法传递对象带query属性的方式去跳转路由。

const host = location.origin
this.$router.push(${host}#/index)
试试这样呢

location.href = location.origin + location.pathname + '#/index'

http://localhost:8080/?flag=0&orderId=eqewrask3408lasj#/payreturn
这个链接你需要改成
http://localhost:8080/#/payreturn?flag=0&orderId=eqewrask3408lasj这样就不会出现你的问题了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题