使用前可以先 console.log(window.location) 看看需要的参数在hash、search、href那个里面,然后选择使用那个
// 获取参数
// 使用前可以先 console.log(window.location) 看看需要的参数在hash、search、href那个里面,然后选择使用那个
export const getUrlParams = (name) => {
const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)') // 构造一个含有目标参数的正则表达式对象
const r = window.location.hash.substr(1).match(reg) // 匹配目标参数 (hash)
// const r = window.location.search.substr(1).match(reg) //匹配目标参数 (histroy)
// const r = window.location.href.substr(1).match(reg) //匹配目标参数 (href)
if (r != null) return unescape(r[2])
return null // 返回参数值
}