微信公众号授权回调 vue网址中带#号的处理

发布时间 2023-08-07 17:32:17作者: 郑州谷多软件

1、改变vue模式为history,小编没有试

2、通过配置nginx实现

      A、替换跳转网址中的#为其他字符串,例如我的

       

        const url = this._getUrl(
            "https://open.weixin.qq.com/connect/oauth2/authorize", {
                appid: this.appId,
                redirect_uri: encodeURIComponent(
                    location.href.replace("#", "virtually")
                ),
                response_type: "code",
                scope: this.scope,
                state: this.state,
            }
        );
        location.href = `${url}#wechat_redirect`;
        console.log("完整的Url");
        console.log(location.href);

   我替换成了virtually,这样返回的时候就是正常的返回了。

2、在nginx中配置跳转

      

location / {
    rewrite ^/virtually/(.*)$ /#$1 permanent;
}

   重启下nginx,搞定。调试只能用微信开发者工具调试了