SOURCE

// 拼接方法一
// hash路由后面跟参数的(拼接到前面去)
let linkSplit = (uri) => {
    if(!uri) return ''
    console.log('初始化前uri: ' + uri)
    let reg = /#.*\?/
    if(reg.test(uri)){
        let _hash = uri.match(reg)[0]
        if(uri.replace(_hash,'').indexOf('?') > -1){
            uri = uri.replace(reg,'&')
        }else{
            uri = uri.replace(reg,'?')
        }
        uri = uri + _hash.replace('?','')
    }
    uri = new URI(uri)
    uri = uri.addQuery("uniwater_utoken", "xxx");
    uri = uri.toString()
    console.log('初始化后uri: ' + uri)
    console.log('——————————')
    return uri
}
// 拼接方法二
// hash路由后面跟参数的(拼接到后去)
let linkSplit2 = (uri) => {
    if(!uri) return ''
    console.log('初始化前uri: ' + uri)
    let reg = /#.*\?/

    if(reg.test(uri) && (uri.match(/\?/g) || []).length == 1){
        let _hash = uri.match(reg)[0]
        uri = uri.replace(_hash,'?')
        uri = new URI(uri)
        uri = uri.addQuery("uniwater_utoken", "xxx");
        uri = uri.toString()
        uri = uri.replace('?',_hash)
    }else{
        uri = new URI(uri)
        uri = uri.addQuery("uniwater_utoken", "xxx");
        uri = uri.toString()
    }
    console.log('初始化后uri: ' + uri)
    console.log('——————————')
    return uri
}
console.log('方法一,hash路由后面跟参数的(拼接到前面去):4种连接')
linkSplit("http://1.1.1.1:8081/wms/index.html#/hash?a=1&b=2&c=3")
linkSplit("http://1.1.1.1:8081/wms/index.html?a=1#/hash?b=2&c=3")
linkSplit("http://1.1.1.1:8081/wms/index.html#/hash")
linkSplit("http://1.1.1.1:8081/wms/index.html?a=1#/hash")
console.log('')
console.log('方法二,hash路由后面跟参数的(拼接到后去):4种连接')
linkSplit2("http://1.1.1.1:8081/wms/index.html#/hash?a=1&b=2&c=3")
linkSplit2("http://1.1.1.1:8081/wms/index.html?a=1#/hash?b=2&c=3")
linkSplit2("http://1.1.1.1:8081/wms/index.html#/hash")
linkSplit2("http://1.1.1.1:8081/wms/index.html?a=1#/hash")
console 命令行工具 X clear

                    
>
console