微信公众号授权跳转地址是VUE路由带#的问题

269 阅读1分钟

背景

今天在写一个自助机扫码跳转到对应的微信公众号页面时,有个详情页是vue的路由写的,地址中带#例如

https://open.weixin.qq.com/connect/oauth2/authorize?appId=wx6a1f86436904cd12&redirect_uri=https://wwww.xxx.cn/home/initial#/detail?a=xx&b=xx&response_type=code&scope=snsapi_base&state=100&connect_redirect=1#wechat_redirect&response_type=code&scope=snsapi_base&state=100&connect_redirect=1#wechat_redirect

,当然实际中的redirect_uri是需要encode一下的,再微信中扫码后发现initial## 号后边的参数均丢失了,查了解决方法说是将vue路由由hash换为history模式就可以,但是让前端小哥看了之后,换成历史模式后页面都没法渲染了,没办法只能从后台入手

解决

前端不行了,只能求助后台了,由于就是apache的系统,也木得ngnix,就使用最简单的redirect重定向了,写一个不带#号的请求,再redirect到目前的请求,说干就干

redirect_uri改为

&redirect_uri=https://wwww.xxx.cn/home/initial/detail?a=xx&b=xx

写一个后台的请求

@RequestMapping("/home/initial/detail")
  public String detail(String a, String b) {

      return "redirect:/home/initial#/detail?a=" + a + "&b=" +b;
  }

曲线救国