Skip to content

Commit

Permalink
feat: 🎸 Search.get兼容hash模式
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingyun2010 committed Nov 21, 2022
1 parent 925f2c2 commit 2803086
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ const Search = {

// 获取search的string
toString() {
return window.location.search.replace(/^\?/, '');
const hash = window.location.hash;
const hashIndex = hash.indexOf('?');
const search =
hash && hashIndex > -1
? hash.substring(hashIndex + 1)
: window.location.search.replace(/^\?/, '');

return search;
},

// map格式转string格式
Expand Down Expand Up @@ -83,14 +90,7 @@ const Search = {
};

export const search = () => {
const hash = window.location.hash;
const hashIndex = hash.indexOf('?');
const search =
hash && hashIndex > -1
? hash.substring(hashIndex + 1)
: window.location.search.replace(/^\?/, '');

return qs.parse(search);
return qs.parse(Search.toString());
};

export default Search;

0 comments on commit 2803086

Please sign in to comment.