Add legacy bang url redirects
This commit is contained in:
@@ -4,6 +4,7 @@ import { RouteObject, redirect } from 'react-router-dom';
|
||||
import { REDIRECTS } from 'apps/dashboard/routes/_redirects';
|
||||
import ConnectionRequired from 'components/ConnectionRequired';
|
||||
import { toAsyncPageRoute } from 'components/router/AsyncRoute';
|
||||
import BangRedirect from 'components/router/BangRedirect';
|
||||
import { toViewManagerPageRoute } from 'components/router/LegacyRoute';
|
||||
import { toRedirectRoute } from 'components/router/Redirect';
|
||||
import ErrorBoundary from 'components/router/ErrorBoundary';
|
||||
@@ -39,6 +40,11 @@ export const EXPERIMENTAL_APP_ROUTES: RouteObject[] = [
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
path: '!/*',
|
||||
Component: BangRedirect
|
||||
},
|
||||
|
||||
/* Redirects for old paths */
|
||||
...REDIRECTS.map(toRedirectRoute)
|
||||
];
|
||||
|
||||
@@ -12,6 +12,7 @@ import AppLayout from '../AppLayout';
|
||||
import { REDIRECTS } from './_redirects';
|
||||
import { ASYNC_USER_ROUTES } from './asyncRoutes';
|
||||
import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes';
|
||||
import BangRedirect from 'components/router/BangRedirect';
|
||||
|
||||
export const STABLE_APP_ROUTES: RouteObject[] = [
|
||||
{
|
||||
@@ -34,6 +35,11 @@ export const STABLE_APP_ROUTES: RouteObject[] = [
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
path: '!/*',
|
||||
Component: BangRedirect
|
||||
},
|
||||
|
||||
/* Redirects for old paths */
|
||||
...REDIRECTS.map(toRedirectRoute)
|
||||
];
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { Navigate, useLocation } from 'react-router-dom';
|
||||
|
||||
const BangRedirect = () => {
|
||||
const location = useLocation();
|
||||
|
||||
const to = useMemo(() => {
|
||||
const _to = {
|
||||
search: location.search,
|
||||
hash: location.hash
|
||||
};
|
||||
|
||||
if (location.pathname.startsWith('/!/')) {
|
||||
return { ..._to, pathname: location.pathname.substring(2) };
|
||||
} else if (location.pathname.startsWith('/!')) {
|
||||
return { ..._to, pathname: location.pathname.replace(/^\/!/, '/') };
|
||||
} else if (location.pathname.startsWith('!')) {
|
||||
return { ..._to, pathname: location.pathname.substring(1) };
|
||||
}
|
||||
}, [ location ]);
|
||||
|
||||
if (!to) return null;
|
||||
|
||||
console.warn('[BangRedirect] You are using a deprecated URL format. This will stop working in a future Jellyfin update.');
|
||||
|
||||
return (
|
||||
<Navigate
|
||||
replace
|
||||
to={to}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default BangRedirect;
|
||||
Reference in New Issue
Block a user