使用前可以先 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 // 返回參數值
}