chore(hash): 新增返回 pathname, 与 layui.url 一致 (#2649)

`path` 将在合适的版本移除
pull/2650/head
贤心 2025-04-18 21:04:38 +08:00 committed by GitHub
parent 3617209874
commit a7267a4b5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -156,7 +156,7 @@
}
};
// 或许配置及临时缓存信息
// 获取配置及临时缓存信息
Class.prototype.cache = Object.assign(config, cache);
/**
@ -521,12 +521,16 @@
var hash = hash || location.hash;
var data = {
path: [],
pathname: [],
search: {},
hash: (hash.match(/[^#](#.*$)/) || [])[1] || '',
href: ''
};
if (!/^#/.test(hash)) return data; // 禁止非路由规范
// 禁止非 hash 路由规范
if (!/^#/.test(hash)) {
return data;
}
hash = hash.replace(/^#/, '');
data.href = hash;
@ -540,6 +544,7 @@
}() : data.path.push(item);
});
data.pathname = data.path; // path → pathname, 与 layui.url 一致
return data;
};