1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Fix url search in hash

This commit is contained in:
Bill Thornton 2022-04-07 16:06:26 -04:00
parent a74ddbb5ca
commit 9b884f1924
3 changed files with 32 additions and 3 deletions

View file

@ -1,6 +1,33 @@
/**
* Gets the url search string.
* This function should be used instead of location.search alone, because the app router
* includes search parameters in the hash portion of the url.
* @returns The url search string.
*/
export const getLocationSearch = () => {
// Return location.search if it exists
if (window.location.search) {
return window.location.search;
}
// Check the entire url in case the search string is in the hash
const index = window.location.href.indexOf('?');
if (index !== -1) {
return window.location.href.substring(index);
}
return '';
};
/**
* Gets the value of a url search parameter by name.
* @param name The parameter name.
* @param url The url to search (optional).
* @returns The parameter value.
*/
export const getParameterByName = (name: string, url?: string | null | undefined) => {
if (!url) {
url = window.location.search;
url = getLocationSearch();
}
// eslint-disable-next-line compat/compat