mirror of
https://github.com/keycloak/keycloak.git
synced 2026-06-09 09:04:21 -04:00
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:
parent
cb0709694f
commit
fa1423d173
2 changed files with 21 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 /> },
|
||||
],
|
||||
},
|
||||
]);
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue