8000 Account UI throws error when opening an unknown path by mabartos · Pull Request #48054 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 20 additions & 3 deletions js/apps/account-ui/src/root/Root.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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[]>();
Expand All @@ -65,7 +79,10 @@ export const Root = () => {
</Page>
),
errorElement: <ErrorPage />,
children: mapRoutes(context, content),
children: [
...mapRoutes(context, content),
{ path: "*", element: <CatchAllRedirect /> },
],
},
]);
},
Expand Down
Loading
0