mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Add legacy bang url redirects
This commit is contained in:
parent
1adaf00cb3
commit
8ddd9ecd9d
3 changed files with 46 additions and 0 deletions
|
@ -11,6 +11,7 @@ import { ASYNC_USER_ROUTES } from './asyncRoutes';
|
||||||
import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes';
|
import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes';
|
||||||
import VideoPage from './video';
|
import VideoPage from './video';
|
||||||
import loadable from '@loadable/component';
|
import loadable from '@loadable/component';
|
||||||
|
import BangRedirect from 'components/router/BangRedirect';
|
||||||
|
|
||||||
const AppLayout = loadable(() => import('../AppLayout'));
|
const AppLayout = loadable(() => import('../AppLayout'));
|
||||||
|
|
||||||
|
@ -40,6 +41,11 @@ export const EXPERIMENTAL_APP_ROUTES: RouteObject[] = [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '!/*',
|
||||||
|
Component: BangRedirect
|
||||||
|
},
|
||||||
|
|
||||||
/* Redirects for old paths */
|
/* Redirects for old paths */
|
||||||
...REDIRECTS.map(toRedirectRoute)
|
...REDIRECTS.map(toRedirectRoute)
|
||||||
];
|
];
|
||||||
|
|
|
@ -11,6 +11,7 @@ import AppLayout from '../AppLayout';
|
||||||
import { REDIRECTS } from './_redirects';
|
import { REDIRECTS } from './_redirects';
|
||||||
import { ASYNC_USER_ROUTES } from './asyncRoutes';
|
import { ASYNC_USER_ROUTES } from './asyncRoutes';
|
||||||
import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes';
|
import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes';
|
||||||
|
import BangRedirect from 'components/router/BangRedirect';
|
||||||
|
|
||||||
export const STABLE_APP_ROUTES: RouteObject[] = [
|
export const STABLE_APP_ROUTES: RouteObject[] = [
|
||||||
{
|
{
|
||||||
|
@ -32,6 +33,11 @@ export const STABLE_APP_ROUTES: RouteObject[] = [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '!/*',
|
||||||
|
Component: BangRedirect
|
||||||
|
},
|
||||||
|
|
||||||
/* Redirects for old paths */
|
/* Redirects for old paths */
|
||||||
...REDIRECTS.map(toRedirectRoute)
|
...REDIRECTS.map(toRedirectRoute)
|
||||||
];
|
];
|
||||||
|
|
34
src/components/router/BangRedirect.tsx
Normal file
34
src/components/router/BangRedirect.tsx
Normal file
|
@ -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;
|
Loading…
Add table
Add a link
Reference in a new issue