Skip to content

Commit

Permalink
fix(h5): improve url query #445 #446
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Jun 10, 2019
1 parent 4458d76 commit 96786a9
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/core/helpers/protocol/route.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import getRealRoute from '../get-real-route'

function encodeQueryString (url) {
if (typeof url === 'string') {
const urls = url.split('?')
if (typeof url !== 'string') {
return url
}
const index = url.indexOf('?')

url = urls[0]
if (index === -1) {
return url
}

const params = [];
(urls[1] || '').split('&').forEach(function (pair) {
if (pair) {
const pairs = pair.split('=')
params.push(pairs[0] + '=' + encodeURIComponent(pairs[1]))
}
})
const query = url.substr(index + 1).trim().replace(/^(\?|#|&)/, '')

return params.length ? url + '?' + params.join('&') : url
if (!query) {
return url
}
return url

url = url.substr(0, index)

const params = []

query.split('&').forEach(param => {

This comment has been minimized.

Copy link
@zhe-he

zhe-he Jun 13, 2019

这里node 原生不是有 querystring 吗
完全没必要自己写吧???

This comment has been minimized.

Copy link
@fxy060608

fxy060608 Jun 13, 2019

Author Collaborator

这里node 原生不是有 querystring 吗
完全没必要自己写吧???

非 node 环境,h5 平台运行时解析的

This comment has been minimized.

Copy link
@RenShine

RenShine Sep 28, 2019

这个可以也兼容一下history模式么?

const parts = param.replace(/\+/g, ' ').split('=')
const key = parts.shift()
const val = parts.length > 0
? parts.join('=')
: ''

params.push(key + '=' + encodeURIComponent(val))
})

return params.length ? url + '?' + params.join('&') : url
}

function createValidator (type) {
Expand Down

0 comments on commit 96786a9

Please sign in to comment.