Account UI throws error when opening an unknown path (#48054)

Closes #40602

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
Co-authored-by: Stan Silvert <ssilvert@redhat.com>
This commit is contained in:
Martin Bartoš 2026-04-15 14:10:08 +02:00 committed by GitHub
parent cb0709694f
commit fa1423d173
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View file

@ -95,6 +95,7 @@ deleteAccount=Delete account
permissionRequest=Permission requests - {{name}}
add=Add
error-invalid-value='{{0}}' has invalid value.
pageNotFound=The requested page was not found.
somethingWentWrong=Something went wrong
somethingWentWrongDescription=Sorry, an unexpected error has occurred.
tryAgain=Try again

View file

@ -1,12 +1,15 @@
import {
ErrorPage,
useAlerts,
useEnvironment,
KeycloakContext,
} from "@keycloak/keycloak-ui-shared";
import { Page, Spinner } from "@patternfly/react-core";
import { Suspense, useState } from "react";
import { AlertVariant, Page, Spinner } from "@patternfly/react-core";
import { Suspense, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import {
createBrowserRouter,
Navigate,
Outlet,
RouteObject,
RouterProvider,
@ -45,6 +48,17 @@ function mapRoutes(
.flat();
}
function CatchAllRedirect() {
const { t } = useTranslation();
const { addAlert } = useAlerts();
useEffect(() => {
addAlert(t("pageNotFound"), AlertVariant.warning);
}, [addAlert, t]);
return <Navigate to="." replace />;
}
export const Root = () => {
const context = useEnvironment<AccountEnvironment>();
const [content, setContent] = useState<RouteObject[]>();
@ -65,7 +79,10 @@ export const Root = () => {
</Page>
),
errorElement: <ErrorPage />,
children: mapRoutes(context, content),
children: [
...mapRoutes(context, content),
{ path: "*", element: <CatchAllRedirect /> },
],
},
]);
},