Routing: Explicitly handle goto redirects (#95559)

This commit is contained in:
Alex Khomenko 2024-11-01 07:52:33 +02:00 committed by GitHub
parent 85ee91aa77
commit f3bdf4455c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
import { Navigate, useParams } from 'react-router-dom-v5-compat';
import { useEffect } from 'react';
import { Navigate, useLocation, useParams } from 'react-router-dom-v5-compat';
import { isTruthy } from '@grafana/data';
import { NavLandingPage } from 'app/core/components/NavLandingPage/NavLandingPage';
@ -534,6 +535,10 @@ export function getAppRoutes(): RouteDescriptor[] {
...extraRoutes,
...getPublicDashboardRoutes(),
...getDataConnectionsRoutes(),
{
path: '/goto/*',
component: HandleGoToRedirect,
},
{
path: '/*',
component: PageNotFound,
@ -571,3 +576,14 @@ function DataSourceEditRoute() {
const { uid = '' } = useParams();
return <Navigate replace to={CONNECTIONS_ROUTES.DataSourcesEdit.replace(':uid', uid)} />;
}
// Explicitly send "goto" URLs to server, bypassing client-side routing
function HandleGoToRedirect() {
const { pathname } = useLocation();
useEffect(() => {
window.location.href = pathname;
}, [pathname]);
return null;
}