permission-react: remove deprecated PermissionedRoute component

Removed the deprecated `PermissionedRoute` component that was incompatible
with React Router v6 stable. Use `RequirePermission` instead.

Also removed the `react-router-dom` dependency from the package since it
is no longer needed.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-04-13 00:40:12 +02:00
parent 774e641e45
commit 53954e1199
6 changed files with 7 additions and 124 deletions
@@ -1,72 +0,0 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ReactElement, ReactNode } from 'react';
import { Route } from 'react-router-dom';
import { useApp } from '@backstage/core-plugin-api';
import { usePermission } from '../hooks';
import {
isResourcePermission,
Permission,
ResourcePermission,
} from '@backstage/plugin-permission-common';
/**
* Returns a React Router Route which only renders the element when authorized. If unauthorized, the Route will render a
* NotFoundErrorPage (see {@link @backstage/core-app-api#AppComponents}).
*
* @public
* @deprecated This component no longer works with the most recent version of `@backstage/core-app-api` and react-router v6, use {@link RequirePermission} instead.
*/
export const PermissionedRoute = (
props: {
caseSensitive?: boolean;
children?: ReactNode;
element?: ReactElement | null;
path?: string;
errorComponent?: ReactElement | null;
} & (
| {
permission: Exclude<Permission, ResourcePermission>;
resourceRef?: never;
}
| {
permission: ResourcePermission;
resourceRef: string | undefined;
}
),
) => {
const { permission, resourceRef, errorComponent, ...otherProps } = props;
const permissionResult = usePermission(
isResourcePermission(permission)
? { permission, resourceRef }
: { permission },
);
const app = useApp();
const { NotFoundErrorPage } = app.getComponents();
let shownElement: ReactElement | null | undefined =
errorComponent === undefined ? <NotFoundErrorPage /> : errorComponent;
if (permissionResult.loading) {
shownElement = null;
} else if (permissionResult.allowed) {
shownElement = props.element;
}
return <Route {...otherProps} element={shownElement} />;
};
@@ -14,6 +14,5 @@
* limitations under the License.
*/
export { PermissionedRoute } from './PermissionedRoute';
export { RequirePermission } from './RequirePermission';
export type { RequirePermissionProps } from './RequirePermission';