mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #3551 from thornbill/fix-location-search
This commit is contained in:
commit
b8a69b892c
3 changed files with 32 additions and 3 deletions
|
@ -12,6 +12,7 @@ import Dashboard from '../scripts/clientUtils';
|
||||||
import ServerConnections from './ServerConnections';
|
import ServerConnections from './ServerConnections';
|
||||||
import alert from './alert';
|
import alert from './alert';
|
||||||
import reactControllerFactory from './reactControllerFactory';
|
import reactControllerFactory from './reactControllerFactory';
|
||||||
|
import { getLocationSearch } from '../utils/url.ts';
|
||||||
|
|
||||||
class AppRouter {
|
class AppRouter {
|
||||||
allRoutes = [];
|
allRoutes = [];
|
||||||
|
@ -120,7 +121,7 @@ class AppRouter {
|
||||||
const regexS = '[\\?&]' + name + '=([^&#]*)';
|
const regexS = '[\\?&]' + name + '=([^&#]*)';
|
||||||
const regex = new RegExp(regexS, 'i');
|
const regex = new RegExp(regexS, 'i');
|
||||||
|
|
||||||
const results = regex.exec(url || window.location.search);
|
const results = regex.exec(url || getLocationSearch());
|
||||||
if (results == null) {
|
if (results == null) {
|
||||||
return '';
|
return '';
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import datetime from '../scripts/datetime';
|
||||||
import DirectoryBrowser from '../components/directorybrowser/directorybrowser';
|
import DirectoryBrowser from '../components/directorybrowser/directorybrowser';
|
||||||
import dialogHelper from '../components/dialogHelper/dialogHelper';
|
import dialogHelper from '../components/dialogHelper/dialogHelper';
|
||||||
import itemIdentifier from '../components/itemidentifier/itemidentifier';
|
import itemIdentifier from '../components/itemidentifier/itemidentifier';
|
||||||
|
import { getLocationSearch } from '../utils/url.ts';
|
||||||
|
|
||||||
export function getCurrentUser() {
|
export function getCurrentUser() {
|
||||||
return window.ApiClient.getCurrentUser(false);
|
return window.ApiClient.getCurrentUser(false);
|
||||||
|
@ -112,7 +113,7 @@ export function navigate(url, preserveQueryString) {
|
||||||
throw new Error('url cannot be null or empty');
|
throw new Error('url cannot be null or empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryString = window.location.search;
|
const queryString = getLocationSearch();
|
||||||
|
|
||||||
if (preserveQueryString && queryString) {
|
if (preserveQueryString && queryString) {
|
||||||
url += queryString;
|
url += queryString;
|
||||||
|
|
|
@ -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) => {
|
export const getParameterByName = (name: string, url?: string | null | undefined) => {
|
||||||
if (!url) {
|
if (!url) {
|
||||||
url = window.location.search;
|
url = getLocationSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue