Skip to main content
Version: Next

RouteFunc

Home > @backstage/frontend-plugin-api > RouteFunc

TS magic for handling route parameters.

Signature:

export type RouteFunc<TParams extends AnyRouteRefParams> = (...[params]: TParams extends undefined ? readonly [] : readonly [params: TParams]) => string;

References: AnyRouteRefParams

Remarks

The extra TS magic here is to require a single params argument if the RouteRef had at least one param defined, but require 0 arguments if there are no params defined. Without this we'd have to pass in empty object to all parameter-less RouteRefs just to make TypeScript happy, or we would have to make the argument optional in which case you might forget to pass it in when it is actually required.