Merge pull request #20 from hankaibo/master

fix: 修复 # 在 ? 之前时,location.search取值为空问题
This commit is contained in:
Tack Chen 2021-12-30 18:33:19 +08:00 committed by GitHub
commit ea5b834aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,8 +7,14 @@ export function getNowTime () {
} }
export function getUrlParam (name) { export function getUrlParam (name) {
const search = window.location.search; let {search} = window.location;
if (search !== '') { const {hash} = window.location;
// # 在 ? 之前,即 http://localhost/#file?key=value会导致 search 为空。
if (search === '' && hash !== '') {
// 为 search 补上前缀'?',以便后面的逻辑处理不变。
search = `?${hash.split('?')[1]}`;
}
if (search !== '' && search !== undefined) {
const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
const r = search.substr(1).match(reg); const r = search.substr(1).match(reg);
if (r != null) { if (r != null) {
@ -103,4 +109,4 @@ export const isMacOs = hasUaName('macintosh');
export const isOldEdge = hasUaName('edge') && !hasUaName('chrome'); export const isOldEdge = hasUaName('edge') && !hasUaName('chrome');
export const isIE = isOldEdge || hasUaName('trident') || hasUaName('msie'); export const isIE = isOldEdge || hasUaName('trident') || hasUaName('msie');