Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(app-routes): do not render old route, redirect instead (#10553)

Vinicius Lourençob846faa1fac5
diff --git a/frontend/src/AppRoutes/Private.tsx b/frontend/src/AppRoutes/Private.tsx
index 3d4c532e1b..4e5ed9df1e 100644
--- a/frontend/src/AppRoutes/Private.tsx
+++ b/frontend/src/AppRoutes/Private.tsx
@@ -1,6 +1,6 @@
import { ReactChild, useCallback, useEffect, useMemo, useState } from 'react';
import { useQuery } from 'react-query';
-import { matchPath, useLocation } from 'react-router-dom';
+import { matchPath, Redirect, useLocation } from 'react-router-dom';
import getLocalStorageApi from 'api/browser/localstorage/get';
import setLocalStorageApi from 'api/browser/localstorage/set';
import getAll from 'api/v1/user/get';
@@ -236,13 +236,7 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
useEffect(() => {
// if it is an old route navigate to the new route
if (isOldRoute) {
- const redirectUrl = oldNewRoutesMapping[pathname];
-
- const newLocation = {
- ...location,
- pathname: redirectUrl,
- };
- history.replace(newLocation);
+ // this will be handled by the redirect component below
return;
}
@@ -296,6 +290,19 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
}
}, [isLoggedInState, pathname, user, isOldRoute, currentRoute, location]);
+ if (isOldRoute) {
+ const redirectUrl = oldNewRoutesMapping[pathname];
+ return (
+ <Redirect
+ to={{
+ pathname: redirectUrl,
+ search: location.search,
+ hash: location.hash,
+ }}
+ />
+ );
+ }
+
// NOTE: disabling this rule as there is no need to have div
return <>{children}</>;
}