diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js index e85fcf9..15ea5fc 100644 --- a/build/webpack.base.conf.js +++ b/build/webpack.base.conf.js @@ -9,7 +9,7 @@ function resolve (dir) { module.exports = { entry: { - 'vue-wechat-auth': './src/index.js' + 'vue-wechat-auth': './src/common.js' }, output: { path: config.build.assetsRoot, diff --git a/src/index.js b/src/index.js index c728316..8a4c01a 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,7 @@ export default { let authCode = weChatAuth.getAuthCode() if ((!to.meta || !to.meta.auth) && !authCode) return true if (!authCode && !weChatAuth.getAccessToken()) { - weChatAuth.openAuthPage(encodeURIComponent(window.location.href)) + weChatAuth.openAuthPage(window.location.href) return false } else if (authCode && !weChatAuth.getAccessToken()) { weChatAuth.getCodeCallback(next) diff --git a/src/wechat-auth.js b/src/wechat-auth.js index 4c4e4ae..2a5ca24 100644 --- a/src/wechat-auth.js +++ b/src/wechat-auth.js @@ -17,7 +17,10 @@ class WeChatAuth { this.config = Object.assign(defaultConfig, config) } - openAuthPage (redirectUri = encodeURIComponent(window.location.href)) { + openAuthPage (redirectUri = window.location.href) { + let redirectUriArr = redirectUri.split('#') + window.sessionStorage.setItem('redirect_path', redirectUriArr[1]) + redirectUri = encodeURIComponent(redirectUriArr[0]) this.removeAccessToken() this.removeAuthCode() let authPageBaseUri = 'https://open.weixin.qq.com/connect/oauth2/authorize' @@ -102,7 +105,7 @@ class WeChatAuth { } getCodeCallback (next) { - return this.config.getCodeCallback(this.getAuthCode(), this.next(next)) + return this.config.getCodeCallback(this.getAuthCode(), this.next(next), window.sessionStorage.getItem('redirect_path')) } }