1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/utils/url.ts
thornbill c5b338dc64 Backport pull request #5732 from jellyfin-web/release-10.9.z
Fix dashboard user page crash

Original-merge: 2d2d5bef94

Merged-by: thornbill <thornbill@users.noreply.github.com>

Backported-by: Bill Thornton <thornbill@users.noreply.github.com>
2024-07-21 01:53:28 -04:00

41 lines
1.2 KiB
TypeScript

/**
* 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 = () => {
// Check location.hash for a search string (this should be the case for our routing library)
let index = window.location.hash.indexOf('?');
if (index !== -1) {
return window.location.hash.substring(index);
}
// Return location.search if it exists
if (window.location.search) {
return window.location.search;
}
// Fallback to checking the entire url
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 = getLocationSearch();
}
// eslint-disable-next-line compat/compat
return new URLSearchParams(url).get(name) || '';
};