mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
Merge pull request #7311 from allenve/master
fix: normalizeLink url处理问题
This commit is contained in:
commit
ad0a019080
@ -9,13 +9,21 @@ export const normalizeLink = (to: string, location = window.location) => {
|
||||
|
||||
const idx = to.indexOf('?');
|
||||
const idx2 = to.indexOf('#');
|
||||
let pathname = ~idx
|
||||
? to.substring(0, idx)
|
||||
: ~idx2
|
||||
? to.substring(0, idx2)
|
||||
: to;
|
||||
let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
|
||||
let hash = ~idx2 ? to.substring(idx2) : location.hash;
|
||||
let pathname = to;
|
||||
let search = '';
|
||||
let hash = location.hash;
|
||||
// host?a=a#b 的情况
|
||||
if (idx < idx2) {
|
||||
pathname = ~idx ? to.substring(0, idx) : ~idx2 ? to.substring(0, idx2) : to;
|
||||
hash = ~idx2 ? to.substring(idx2) : location.hash;
|
||||
search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
|
||||
}
|
||||
// host#b?a=a 的情况
|
||||
else if (idx > idx2) {
|
||||
pathname = ~idx2 ? to.substring(0, idx2) : ~idx ? to.substring(0, idx) : to;
|
||||
hash = ~idx2 ? to.substring(idx2, ~idx ? idx : undefined) : location.hash;
|
||||
search = ~idx ? to.substring(idx) : '';
|
||||
}
|
||||
|
||||
if (!pathname) {
|
||||
pathname = location.pathname;
|
||||
@ -33,5 +41,6 @@ export const normalizeLink = (to: string, location = window.location) => {
|
||||
pathname = paths.concat(pathname).join('/');
|
||||
}
|
||||
|
||||
return pathname + search + hash;
|
||||
const rest = idx < idx2 ? search + hash : hash + search;
|
||||
return pathname + rest;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user