获取普通地址url参数
/**
*
* 例如:http://localhost:8890/outpatient?userId=204457891868897280
*
* @param {String} name
* @return {Boolean | String} 返回获取值
*
*/
export const getUrlParam = name =>{
const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
const r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return false;
}
获取hash模式地址url参数
/**
*
* 例如:http://localhost:8890/#/outpatient?userId=204457891868897280
*
* @param {String} name
* @return {Boolean | String} 返回获取值
*
*/
export const getUrlHashParam =name =>{
const w = window.location.hash.indexOf("?");
const query = window.location.hash.substring(w + 1);
const vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split("=");
if (pair[0] == name) {
return pair[1];
}
}
return false;
}