| 1 |
export default function useQueryParams() { |
| 2 |
const urlSearchParams = new URLSearchParams( window.location.search ), |
| 3 |
urlParams = Object.fromEntries( urlSearchParams.entries() ), |
| 4 |
hashValue = location.hash.match( /\?(.+)/ )?.[ 1 ], |
| 5 |
hashParams = {}; |
| 6 |
|
| 7 |
if ( hashValue ) { |
| 8 |
hashValue.split( '&' ).forEach( ( pair ) => { |
| 9 |
const [ key, value ] = pair.split( '=' ); |
| 10 |
|
| 11 |
hashParams[ key ] = value; |
| 12 |
} ); |
| 13 |
} |
| 14 |
|
| 15 |
// Merging the URL params with the hash params. |
| 16 |
const queryParams = { |
| 17 |
...urlParams, |
| 18 |
...hashParams, |
| 19 |
}; |
| 20 |
|
| 21 |
return { |
| 22 |
getAll: () => queryParams, |
| 23 |
}; |
| 24 |
} |
| 25 |
|