frontend-plugin-api: removed new useRouteRef

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-06 16:43:24 +02:00
parent cbed529916
commit 4461d87d5a
9 changed files with 14 additions and 126 deletions
@@ -333,7 +333,4 @@ export type PortableSchema<TOutput> = {
parse: (input: unknown) => TOutput;
schema: JsonObject;
};
// @public (undocumented)
export function useRouteRef(routeRef: RouteRef<any>): () => string;
```
@@ -24,4 +24,3 @@ export * from './components';
export * from './extensions';
export * from './schema';
export * from './wiring';
export * from './routing';
@@ -1,17 +0,0 @@
/*
* Copyright 2023 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.
*/
export { useRouteRef } from './useRouteRef';
@@ -1,38 +0,0 @@
/*
* Copyright 2023 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 { RouteRef } from '@backstage/core-plugin-api';
// eslint-disable-next-line @backstage/no-forbidden-package-imports
import { RoutingContext } from '@backstage/frontend-app-api/src/routing/RoutingContext';
import { useContext, useMemo } from 'react';
import { useLocation } from 'react-router-dom';
/** @public */
export function useRouteRef(routeRef: RouteRef<any>): () => string {
const { pathname } = useLocation();
const resolver = useContext(RoutingContext);
const routeFunc = useMemo(
() => resolver && resolver.resolve(routeRef, { pathname }),
[resolver, routeRef, pathname],
);
if (!routeFunc) {
throw new Error(`Failed to resolve routeRef ${routeRef}`);
}
return routeFunc;
}