Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uni对h5环境下的链接query解析跳转有误 #1433

Closed
xiaobeilo opened this issue Mar 19, 2020 · 0 comments
Closed

uni对h5环境下的链接query解析跳转有误 #1433

xiaobeilo opened this issue Mar 19, 2020 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@xiaobeilo
Copy link

问题描述
h5页面在history模式下, 通过vue-cli-plugin-uni/packages/h5-vue-router处理后的链接会解析错误

复现步骤
[复现问题的步骤]

  1. 设置manifest.json下的h5.router为history
  2. npm run dev:h5
  3. 打开链接 http://localhost:8080/?key=:value
    4.观察链接

[或者可以直接贴源代码]

预期结果
链接不应该发生跳转, 跳转也应该是一个正确合法的链接地址

实际结果
打开页面之后会发现链接 被修改成了http://localhost:8080/[object%20Object]

系统信息:

  • 发行平台: H5平台
  • 操作系统 [如 iOS 12.1.2、Android 7.0]
  • HBuilderX版本 [如使用HBuilderX,则需提供 HBuilderX 版本号]
  • uni-app版本 [如使用Vue-cli创建/运行项目,则提供npm run info的运行结果]
  • 设备信息 [如 iPhone8 Plus]
    uni-app v2.6.5
    uni-app cli v2.0.0-26520200314001

Environment Info:

System:
OS: macOS 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Binaries:
Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
Browsers:
Chrome: 80.0.3987.149
Firefox: 72.0.1
Safari: 12.1.2
npmPackages:
@dcloudio/uni-app-plus: ^2.0.0-25120200103006 => 2.0.0-25120200103006
@dcloudio/uni-app-plus-nvue: 0.0.1
@dcloudio/uni-app-plus-nvue-v8: 0.0.1
@dcloudio/uni-cli-shared: ^2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/uni-h5: ^2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/uni-helper-json: * => 1.0.5
@dcloudio/uni-migration: ^2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/uni-mp-alipay: ^2.0.0-25120200103006 => 2.0.0-25120200103006
@dcloudio/uni-mp-baidu: ^2.0.0-25120200103006 => 2.0.0-25120200103006
@dcloudio/uni-mp-qq: ^2.0.0-25120200103006 => 2.0.0-25120200103006
@dcloudio/uni-mp-toutiao: ^2.0.0-25120200103006 => 2.0.0-25120200103006
@dcloudio/uni-mp-weixin: ^2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/uni-stat: ^2.0.0-25120200103006 => 2.0.0-25120200103006 (2.0.0-26520200314001)
@dcloudio/uni-template-compiler: ^2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/vue-cli-plugin-hbuilderx: ~2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/vue-cli-plugin-uni: ~2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/vue-cli-plugin-uni-optimize: ~2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/webpack-uni-mp-loader: ^2.0.0-26520200314001 => 2.0.0-26520200314001
@dcloudio/webpack-uni-nvue-loader: 0.0.1
@dcloudio/webpack-uni-pages-loader: ^2.0.0-26520200314001 => 2.0.0-26520200314001
@vue/babel-helper-vue-jsx-merge-props: 1.0.0
@vue/babel-plugin-transform-vue-jsx: 1.1.2
@vue/babel-preset-app: 3.12.1
@vue/babel-preset-jsx: 1.1.2
@vue/babel-sugar-functional-vue: 1.1.2
@vue/babel-sugar-inject-h: 1.1.2
@vue/babel-sugar-v-model: 1.1.2
@vue/babel-sugar-v-on: 1.1.2
@vue/cli-overlay: 4.2.2
@vue/cli-plugin-babel: 3.5.1 => 3.5.1
@vue/cli-plugin-router: 4.2.2
@vue/cli-plugin-vuex: 4.2.2
@vue/cli-service: ~4.2.0 => 4.2.2
@vue/cli-shared-utils: 3.12.1
@vue/component-compiler-utils: 3.1.1 (3.1.1)
@vue/preload-webpack-plugin: 1.1.1
@vue/web-component-wrapper: 1.2.0
mpvue-page-factory: 1.0.1
mpvue-template-compiler: 1.0.13
uni-h5-vue: 2.6.10
uni-mp-vue: 2.6.10
vue: ^2.6.11 => 2.6.11
vue-hot-reload-api: 2.3.4
vue-loader: 15.9.0 (15.9.0)
vue-router: 3.0.1
vue-style-loader: 4.1.2
vue-template-compiler: ^2.6.11 => 2.6.11
vue-template-es2015-compiler: 1.9.1
vuex: ^3.0.1 => 3.1.2
npmGlobalPackages:
@vue/cli: 4.2.2

补充信息
已调试代码, 猜测原因如下:

// node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.esm.js
//2280行:
HTML5History.prototype.ensureURL = function ensureURL (push ) {
    if (getLocation(this.base) !== this.current.fullPath) {
// getLocation得到的是一个decode的url, 而this.current.fullPath并没有经过decode, 因此带 ":"的链接在该条件下会不相等, 继而让代码执行发生了后续错误的跳转行为
      var current = cleanPath(this.base + this.current.fullPath);
      // fixed by xxxxxx
      var location = {
        path: current,
        params: {
          __id__: this.current.params.__id__
        }
      };
      push ? pushState(location, location.params.__id__) : replaceState(location, location.params.__id__);
    }
  }; 
// 2306行:
function getLocation (base) {
  var path = decodeURI(window.location.pathname);
  if (base && path.indexOf(base) === 0) {
    path = path.slice(base.length);
  }
  return (path || '/') + window.location.search + window.location.hash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants