mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
22 lines
742 B
TypeScript
22 lines
742 B
TypeScript
import type {PlainRoute} from 'react-router';
|
|
|
|
/**
|
|
* For all routes with a `path`, find the first route without a route param (e.g. :apiKey)
|
|
*
|
|
* @param routes A list of react-router route objects
|
|
* @param route If given, will only take into account routes between `route` and end of the routes list
|
|
* @return Object Returns a react-router route object
|
|
*/
|
|
export default function findFirstRouteWithoutRouteParam(
|
|
routes: PlainRoute[],
|
|
route?: PlainRoute
|
|
) {
|
|
const routeIndex = route !== undefined ? routes.indexOf(route) : -1;
|
|
const routesToSearch = route && routeIndex > -1 ? routes.slice(routeIndex) : routes;
|
|
|
|
return (
|
|
routesToSearch.filter(({path}) => !!path).find(({path}) => !path?.includes(':')) ||
|
|
route
|
|
);
|
|
}
|