Route Content - Key: {routeKey}
diff --git a/src/lib/testing/test-utils.ts b/src/lib/testing/test-utils.ts
index b4580aa..517eb62 100644
--- a/src/lib/testing/test-utils.ts
+++ b/src/lib/testing/test-utils.ts
@@ -158,10 +158,10 @@ type RouteSpecs = {
specs: Omit
& { name?: string; };
}
-export function addRoutes(router: RouterEngine, routes: { matching?: number; nonMatching?: number; }, ...add: (RouteInfo & { name?: string; })[]): string[];
-export function addRoutes(router: RouterEngine, routes: { matching?: RouteSpecs ; nonMatching?: RouteSpecs; }, ...add: (RouteInfo & { name?: string; })[]): string[];
-export function addRoutes(router: RouterEngine, routes: { matching?: number | RouteSpecs; nonMatching?: number | RouteSpecs; }, ...add: (RouteInfo & { name?: string; })[]): string[] {
- const { matching = 0, nonMatching = 0 } = routes;
+export function addRoutes(router: RouterEngine, routes: undefined | { matching?: number; nonMatching?: number; }, ...add: (RouteInfo & { name?: string; })[]): string[];
+export function addRoutes(router: RouterEngine, routes: undefined | { matching?: RouteSpecs ; nonMatching?: RouteSpecs; }, ...add: (RouteInfo & { name?: string; })[]): string[];
+export function addRoutes(router: RouterEngine, routes: undefined | { matching?: number | RouteSpecs; nonMatching?: number | RouteSpecs; }, ...add: (RouteInfo & { name?: string; })[]): string[] {
+ const { matching = 0, nonMatching = 0 } = routes || {};
const routeNames: string[] = [];
[[matching, addMatchingRoute] as const, [nonMatching, addNonMatchingRoute] as const].forEach(x => {
const [r, fn] = x;
diff --git a/src/lib/types.ts b/src/lib/types.ts
index 6bde376..e689fbf 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -47,13 +47,78 @@ export type RouteStatus = {
*
* This is only available if the route has matched.
*/
- routeParams?: Record;
+ routeParams?: RouteParamsRecord;
}
+/**
+ * Resolves the parameter name from potentially optional parameters.
+ */
+export type ParamName = T extends `${infer P}?` ? P : T;
+
+/**
+ * Extracts the parameters from a route pattern.
+ */
+export type RouteParameters = T extends string
+ ? T extends `${string}:${infer Param}/${infer Rest}`
+ ? ParamName | RouteParameters
+ : T extends `${string}:${infer Param}`
+ ? ParamName
+ : T extends `${string}/*`
+ ? 'rest'
+ : T extends '*'
+ ? 'rest'
+ : never
+ : string;
+
+/**
+ * Defines a record type mapping route parameter names to their values.
+ */
+export type RouteParamsRecord = T extends "" ? Record : Record, ParameterValue>;
+
+/**
+ * Defines a record type mapping route identifiers to their route matching status.
+ */
+export type RouteStatusRecord = Record;
+
+/**
+ * Defines the context type provided by router components through their `children` snippet.
+ */
+export type RouterChildrenContext = {
+ /**
+ * Holds the state data associated to the current routing universe.
+ */
+ state: any;
+ /**
+ * Holds the route status data for all routes managed by the router.
+ */
+ rs: RouteStatusRecord;
+};
+
+/**
+ * Defines the context type provided by route components through their `children` snippet.
+ */
+export type RouteChildrenContext = RouterChildrenContext & {
+ /**
+ * Holds the route parameters for the route.
+ */
+ rp?: RouteParamsRecord;
+};
+
+/**
+ * Defines the context type provided by link components through their `children` snippet.
+ */
+export type LinkChildrenContext = Omit & {
+ /**
+ * Holds the route status data for all routes managed by the parent router, if said parent
+ * exists.
+ */
+ rs?: RouteStatusRecord | undefined;
+};
+
/**
* Defines the shape of predicate functions that are used to further test if a route should be matched.
*/
-export type AndUntyped = (params: Record | undefined) => boolean;
+export type AndUntyped = (params: RouteParamsRecord | undefined) => boolean;
/**
* Defines the core properties of a route definition.
@@ -114,7 +179,7 @@ export type RedirectedRouteInfo = NoIgnoreForFallback & {
* The HREF to navigate to (via `location.navigate()` or `location.goTo()`). It can be a string or a function that
* receives the matched route parameters and returns a string.
*/
- href: string | ((routeParams: Record | undefined) => string);
+ href: string | ((routeParams: RouteParamsRecord | undefined) => string);
} & ({
/**
* Indicates that the redirection should use the `Location.goTo` method.