提交 96786a98 编写于 作者: fxy060608's avatar fxy060608

fix(h5): improve url query #445 #446

上级 4458d76c
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('?')
if (index === -1) {
return url
}
url = urls[0]
const query = url.substr(index + 1).trim().replace(/^(\?|#|&)/, '')
const params = [];
(urls[1] || '').split('&').forEach(function (pair) {
if (pair) {
const pairs = pair.split('=')
params.push(pairs[0] + '=' + encodeURIComponent(pairs[1]))
if (!query) {
return url
}
url = url.substr(0, index)
const params = []
query.split('&').forEach(param => {
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
}
return url
}
function createValidator (type) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册