mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 19:16:01 +08:00
fix: redirect old logs routes to new routes (#4584)
This commit is contained in:
parent
f3bc1a8f8a
commit
f2d5d21581
@ -20,11 +20,16 @@ import { UPDATE_USER_IS_FETCH } from 'types/actions/app';
|
|||||||
import AppReducer from 'types/reducer/app';
|
import AppReducer from 'types/reducer/app';
|
||||||
import { routePermission } from 'utils/permission';
|
import { routePermission } from 'utils/permission';
|
||||||
|
|
||||||
import routes, { LIST_LICENSES } from './routes';
|
import routes, {
|
||||||
|
LIST_LICENSES,
|
||||||
|
oldNewRoutesMapping,
|
||||||
|
oldRoutes,
|
||||||
|
} from './routes';
|
||||||
import afterLogin from './utils';
|
import afterLogin from './utils';
|
||||||
|
|
||||||
function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
|
function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
|
||||||
const { pathname } = useLocation();
|
const location = useLocation();
|
||||||
|
const { pathname } = location;
|
||||||
|
|
||||||
const mapRoutes = useMemo(
|
const mapRoutes = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@ -59,6 +64,8 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
|
|||||||
|
|
||||||
const currentRoute = mapRoutes.get('current');
|
const currentRoute = mapRoutes.get('current');
|
||||||
|
|
||||||
|
const isOldRoute = oldRoutes.indexOf(pathname) > -1;
|
||||||
|
|
||||||
const isLocalStorageLoggedIn =
|
const isLocalStorageLoggedIn =
|
||||||
getLocalStorageApi(LOCALSTORAGE.IS_LOGGED_IN) === 'true';
|
getLocalStorageApi(LOCALSTORAGE.IS_LOGGED_IN) === 'true';
|
||||||
|
|
||||||
@ -158,6 +165,16 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async (): Promise<void> => {
|
(async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
if (isOldRoute) {
|
||||||
|
const redirectUrl = oldNewRoutesMapping[pathname];
|
||||||
|
|
||||||
|
const newLocation = {
|
||||||
|
...location,
|
||||||
|
pathname: redirectUrl,
|
||||||
|
};
|
||||||
|
history.replace(newLocation);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentRoute) {
|
if (currentRoute) {
|
||||||
const { isPrivate, key } = currentRoute;
|
const { isPrivate, key } = currentRoute;
|
||||||
|
|
||||||
|
@ -279,6 +279,13 @@ const routes: AppRoutes[] = [
|
|||||||
key: 'LIVE_LOGS',
|
key: 'LIVE_LOGS',
|
||||||
isPrivate: true,
|
isPrivate: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: ROUTES.LOGS_PIPELINES,
|
||||||
|
exact: true,
|
||||||
|
component: PipelinePage,
|
||||||
|
key: 'LOGS_PIPELINES',
|
||||||
|
isPrivate: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: ROUTES.LOGIN,
|
path: ROUTES.LOGIN,
|
||||||
exact: true,
|
exact: true,
|
||||||
@ -307,13 +314,6 @@ const routes: AppRoutes[] = [
|
|||||||
key: 'SOMETHING_WENT_WRONG',
|
key: 'SOMETHING_WENT_WRONG',
|
||||||
isPrivate: false,
|
isPrivate: false,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: ROUTES.LOGS_PIPELINES,
|
|
||||||
exact: true,
|
|
||||||
component: PipelinePage,
|
|
||||||
key: 'LOGS_PIPELINES',
|
|
||||||
isPrivate: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: ROUTES.BILLING,
|
path: ROUTES.BILLING,
|
||||||
exact: true,
|
exact: true,
|
||||||
@ -353,6 +353,20 @@ export const LIST_LICENSES: AppRoutes = {
|
|||||||
key: 'LIST_LICENSES',
|
key: 'LIST_LICENSES',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const oldRoutes = [
|
||||||
|
'/pipelines',
|
||||||
|
'/logs/old-logs-explorer',
|
||||||
|
'/logs-explorer',
|
||||||
|
'/logs-explorer/live',
|
||||||
|
];
|
||||||
|
|
||||||
|
export const oldNewRoutesMapping: Record<string, string> = {
|
||||||
|
'/pipelines': '/logs/pipelines',
|
||||||
|
'/logs/old-logs-explorer': '/logs/old-logs-explorer',
|
||||||
|
'/logs-explorer': '/logs/logs-explorer',
|
||||||
|
'/logs-explorer/live': '/logs/logs-explorer/live',
|
||||||
|
};
|
||||||
|
|
||||||
export interface AppRoutes {
|
export interface AppRoutes {
|
||||||
component: RouteProps['component'];
|
component: RouteProps['component'];
|
||||||
path: RouteProps['path'];
|
path: RouteProps['path'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user