1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/navigation/match-route.injectable.ts

22 lines
814 B
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { match, RouteProps } from "react-router";
import { matchPath } from "react-router";
import observableHistoryInjectable from "./observable-history.injectable";
export type MatchRoute = <Params extends { [K in keyof Params]?: string }>(route: string | string[] | RouteProps) => match<Params> | null;
const matchRouteInjectable = getInjectable({
id: "match-route",
instantiate: (di): MatchRoute => {
const observableHistory = di.inject(observableHistoryInjectable);
return (route) => matchPath(observableHistory.location.pathname, route);
},
});
export default matchRouteInjectable;