vue hash 支付 回调
我们在做支付页面成功后重新回调到带有hash值的页面,后台是无法获取到#后面的内容如:http://192.168.31.62:8080/#/about,/about是获取不到的
但是vue项目都需要支持hash。
解决:
在首页路由的created加入以下代码:
function getParams(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var r = window.location.search.substr(1).match(reg); if(r) { return decodeURI(r[2]); } return null; } created() { if( getParams('id')==111 ){ var url = window.location.protocol + "//" + window.location.host + "/?time=" + Math.random() + "#/about" window.location.href = url } },
前端回调地址把
http://192.168.31.62:8080/#/about改成http://192.168.31.62:8080/?id=111