@analogjs/router 3.0.0-alpha.90 → 3.0.0-alpha.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,246 @@
1
+ import { type ActivatedRoute, type ResolveFn } from '@angular/router';
2
+ /**
3
+ * Typed route path utilities for Analog.
4
+ *
5
+ * This module provides:
6
+ * - The `AnalogRouteTable` base interface (augmented by generated code)
7
+ * - The `AnalogRoutePath` union type
8
+ * - The `toRoute()` URL builder function
9
+ *
10
+ * Link construction does not require an injection context.
11
+ */
12
+ /**
13
+ * Base interface for the typed route table.
14
+ *
15
+ * This interface is augmented by generated code in `src/routeTree.gen.d.ts`.
16
+ * Without the generated declaration, typed helpers reject route paths.
17
+ */
18
+ export interface AnalogRouteTable {
19
+ }
20
+ /**
21
+ * Union of all valid route paths.
22
+ *
23
+ * When routes are generated, this is a string literal union.
24
+ * Without the generated declaration, this is `never`.
25
+ */
26
+ export type AnalogRoutePath = Extract<keyof AnalogRouteTable, string>;
27
+ type QueryValue = string | number | boolean;
28
+ /**
29
+ * Query values accepted when building URLs. Angular converts them to strings
30
+ * and drops `null` and `undefined`, or removes those keys when merging.
31
+ */
32
+ type RouteQueryInput = Record<string, QueryValue | QueryValue[] | null | undefined>;
33
+ /**
34
+ * Options for building a route URL.
35
+ */
36
+ export interface RoutePathOptionsBase {
37
+ params?: Record<string, string | number | (string | number)[] | undefined>;
38
+ query?: RouteQueryInput;
39
+ hash?: string;
40
+ }
41
+ /** Raw parameter types from the generated route table. */
42
+ export type RouteParamsOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
43
+ params: infer Params;
44
+ } ? Params : Record<string, unknown> : Record<string, unknown>;
45
+ /**
46
+ * Extracts the raw output type for route query params.
47
+ */
48
+ export type RouteQueryOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
49
+ query: infer O;
50
+ } ? O : Record<string, string | string[] | undefined> : Record<string, string | string[] | undefined>;
51
+ type RequiredRouteParamKeys<Params> = Params extends Record<string, never> ? never : {
52
+ [K in keyof Params]-?: Record<string, never> extends Pick<Params, K> ? never : K;
53
+ }[keyof Params];
54
+ type HasRequiredRouteParams<Params> = [RequiredRouteParamKeys<Params>] extends [
55
+ never
56
+ ] ? false : true;
57
+ type RouteParamsInput<Params> = {
58
+ [K in keyof Params]: Exclude<Params[K], undefined> extends string[] ? undefined extends Params[K] ? (string | number)[] : [string | number, ...(string | number)[]] : Exclude<Params[K], undefined> extends string ? string | number : Params[K];
59
+ };
60
+ /**
61
+ * Typed options that infer params from the route table when available.
62
+ */
63
+ export type RoutePathOptions<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
64
+ params: infer Params;
65
+ } ? Params extends Record<string, never> ? {
66
+ params?: never;
67
+ query?: RouteQueryInput;
68
+ hash?: string;
69
+ } : HasRequiredRouteParams<Params> extends true ? {
70
+ params: RouteParamsInput<Params>;
71
+ query?: RouteQueryInput;
72
+ hash?: string;
73
+ } : {
74
+ params?: RouteParamsInput<Params>;
75
+ query?: RouteQueryInput;
76
+ hash?: string;
77
+ } : RoutePathOptionsBase : RoutePathOptionsBase;
78
+ /**
79
+ * Conditional args: require options when the route has params.
80
+ */
81
+ export type RoutePathArgs<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
82
+ params: infer Params;
83
+ } ? Params extends Record<string, never> ? [options?: RoutePathOptions<P>] : HasRequiredRouteParams<Params> extends true ? [options: RoutePathOptions<P>] : [options?: RoutePathOptions<P>] : [options?: RoutePathOptionsBase] : [options?: RoutePathOptionsBase];
84
+ type EmptyObject = Record<never, never>;
85
+ type Simplify<T> = {
86
+ [K in keyof T]: T[K];
87
+ };
88
+ type Merge<A, B> = Omit<A, keyof B> & B;
89
+ type MetaObject<T> = unknown extends T ? EmptyObject : string extends keyof NonNullable<T> ? Record<string, unknown> : NonNullable<T>;
90
+ type StaticRouteData<Meta> = Meta extends {
91
+ data?: infer Data;
92
+ } ? MetaObject<Data> : EmptyObject;
93
+ type RouteResolvers<Meta> = Meta extends {
94
+ resolve?: infer Resolvers;
95
+ } ? MetaObject<Resolvers> : EmptyObject;
96
+ type ResolvedRouteData<Meta> = {
97
+ [K in keyof RouteResolvers<Meta>]: RouteResolvers<Meta>[K] extends ResolveFn<infer T> ? T : unknown;
98
+ };
99
+ type RouteMetaData<Meta> = Merge<StaticRouteData<Meta>, ResolvedRouteData<Meta>>;
100
+ type InheritedRouteData<Metas, Data = EmptyObject> = Metas extends [
101
+ infer Meta,
102
+ ...infer Rest
103
+ ] ? InheritedRouteData<Rest, Merge<Data, RouteMetaData<Exclude<Meta, {
104
+ redirectTo: string;
105
+ }>>>> : Data;
106
+ type RouteResourceMap<Meta> = Meta extends {
107
+ resources?: (ctx: never) => infer R;
108
+ } ? Awaited<R> extends Record<PropertyKey, unknown> ? Awaited<R> : EmptyObject : EmptyObject;
109
+ type PageRouteMetas<P extends keyof AnalogRouteTable> = [
110
+ ...(AnalogRouteTable[P] extends {
111
+ layoutRouteMeta: infer Metas extends unknown[];
112
+ } ? Metas : []),
113
+ ...(AnalogRouteTable[P] extends {
114
+ routeMeta: infer Meta;
115
+ } ? [Meta] : [])
116
+ ];
117
+ type PageLoadData<P extends keyof AnalogRouteTable> = AnalogRouteTable[P] extends {
118
+ load: unknown;
119
+ } ? {
120
+ load: RouteLoadOutput<P>;
121
+ } : EmptyObject;
122
+ /** Route paths whose page has a server `load` function. */
123
+ export type AnalogRouteWithLoad = {
124
+ [P in AnalogRoutePath]: AnalogRouteTable[P] extends {
125
+ load: unknown;
126
+ } ? P : never;
127
+ }[AnalogRoutePath];
128
+ /** Resolved result of a page's server `load` function. */
129
+ export type RouteLoadOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
130
+ load: (...args: never[]) => infer R;
131
+ } ? Awaited<R> : never : never;
132
+ /**
133
+ * Data for a page route: static `routeMeta.data` and `routeMeta.resolve`
134
+ * results from its layouts and the page, and the page's server `load` result.
135
+ */
136
+ export type RouteDataOutput<P extends string> = P extends keyof AnalogRouteTable ? Simplify<Omit<InheritedRouteData<PageRouteMetas<P>>, 'load'> & PageLoadData<P>> : Record<string, unknown>;
137
+ /**
138
+ * Resources for a page route: `routeMeta.resources` results defined on the page.
139
+ */
140
+ export type RouteResourcesOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
141
+ routeMeta: infer Meta;
142
+ } ? Simplify<RouteResourceMap<Exclude<Meta, {
143
+ redirectTo: string;
144
+ }>>> : EmptyObject : ActivatedRoute extends {
145
+ resources: infer Resources;
146
+ } ? Resources : EmptyObject;
147
+ type SplitPath<S extends string> = S extends '' ? [] : S extends `${infer Head}/${infer Tail}` ? [Head, ...SplitPath<Tail>] : [S];
148
+ type Segments<P extends string> = P extends `/${infer Rest}` ? SplitPath<Rest> : SplitPath<P>;
149
+ type JoinPath<S extends string[]> = S extends [
150
+ infer Head extends string,
151
+ ...infer Tail extends string[]
152
+ ] ? Tail extends [] ? Head : `${Head}/${JoinPath<Tail>}` : '';
153
+ type Pop<S extends string[]> = S extends [
154
+ ...infer Init extends string[],
155
+ string
156
+ ] ? Init : [];
157
+ type ParentPath<P extends string> = `/${JoinPath<Pop<Segments<P>>>}`;
158
+ type LastSegment<P extends string> = Segments<P> extends [...string[], infer Last extends string] ? Last : never;
159
+ type ResolveSegments<Base extends string[], Parts extends string[]> = Parts extends [infer Head extends string, ...infer Tail extends string[]] ? ResolveSegments<Head extends '.' ? Base : Head extends '..' ? Pop<Base> : [...Base, Head], Tail> : Base;
160
+ /** Resolves a relative target against the `From` route path. */
161
+ export type ResolveRoutePath<From extends string, To extends string> = To extends `/${string}` ? To : `/${JoinPath<ResolveSegments<Segments<From>, SplitPath<To>>>}`;
162
+ type PathPrefix<Base extends string> = Base extends '/' ? '/' : `${Base}/`;
163
+ /** Route paths nested below `Base`, relative to it. */
164
+ type ChildPaths<Base extends string, P extends string = AnalogRoutePath> = P extends `${PathPrefix<Base>}${infer Rest}` ? Rest extends '' ? never : Rest : never;
165
+ type AncestorTargets<From extends string, Up extends string> = From extends '/' ? never : (ParentPath<From> extends AnalogRoutePath ? Up : never) | `${Up}/${Exclude<ChildPaths<ParentPath<From>>, LastSegment<From> | `${LastSegment<From>}/${string}`>}` | AncestorTargets<ParentPath<From>, `${Up}/..`>;
166
+ /** Relative targets from `From`: `.`, `./child`, `..`, and `../sibling`. */
167
+ export type RelativeRouteTarget<From extends string> = '.' | `./${ChildPaths<From>}` | AncestorTargets<From, '..'>;
168
+ /** Absolute route paths plus targets relative to `From`. */
169
+ export type ScopedRouteTarget<From extends string> = AnalogRoutePath | RelativeRouteTarget<From>;
170
+ type SegmentParam<S extends string> = S extends `[[...${infer Name}]]` ? Name : S extends `[...${infer Name}]` ? Name : S extends `[${infer Name}]` ? Name : never;
171
+ type SharedParams<A extends string[], B extends string[]> = A extends [
172
+ infer Head extends string,
173
+ ...infer ATail extends string[]
174
+ ] ? B extends [Head, ...infer BTail extends string[]] ? SegmentParam<Head> | SharedParams<ATail, BTail> : never : never;
175
+ type WithOptional<T, K extends PropertyKey> = Simplify<Omit<T, K> & Partial<Pick<T, Extract<keyof T, K>>>>;
176
+ type ScopedParamsInput<From extends string, To extends string> = WithOptional<RouteParamsInput<RouteParamsOutput<To>>, SharedParams<Segments<From>, Segments<To>>>;
177
+ /** Options for a route path; params shared with `From` default to current values. */
178
+ export type ScopedRoutePathOptions<From extends string, To extends string> = RouteParamsOutput<To> extends Record<string, never> ? {
179
+ params?: never;
180
+ query?: RouteQueryInput;
181
+ hash?: string;
182
+ } : HasRequiredRouteParams<ScopedParamsInput<From, To>> extends true ? {
183
+ params: ScopedParamsInput<From, To>;
184
+ query?: RouteQueryInput;
185
+ hash?: string;
186
+ } : {
187
+ params?: ScopedParamsInput<From, To>;
188
+ query?: RouteQueryInput;
189
+ hash?: string;
190
+ };
191
+ /** Conditional args for a target resolved against `From`. */
192
+ export type ScopedRoutePathArgs<From extends string, Target extends string> = ScopedRoutePathOptions<From, ResolveRoutePath<From, Target>> extends infer O ? EmptyObject extends O ? [options?: O] : [options: O] : never;
193
+ /**
194
+ * Result of `toRoute()` — contains properties that map directly
195
+ * to Angular's `[routerLink]`, `[queryParams]`, and `[fragment]` inputs.
196
+ */
197
+ export interface RouteLinkResult {
198
+ path: string[];
199
+ queryParams: RouteQueryInput | null;
200
+ fragment: string | undefined;
201
+ }
202
+ /**
203
+ * Builds a typed route link object from a route path pattern and options.
204
+ *
205
+ * The returned object separates path, query params, and fragment for
206
+ * direct use with Angular's routerLink directive inputs.
207
+ *
208
+ * @example
209
+ * toRoute('/about')
210
+ * // → { path: ['/', 'about'], queryParams: null, fragment: undefined }
211
+ *
212
+ * toRoute('/users/[id]', { params: { id: '42' } })
213
+ * // → { path: ['/', 'users', '42'], queryParams: null, fragment: undefined }
214
+ *
215
+ * toRoute('/users/[id]', { params: { id: '42' }, query: { tab: 'settings' }, hash: 'bio' })
216
+ * // → { path: ['/', 'users', '42'], queryParams: { tab: 'settings' }, fragment: 'bio' }
217
+ *
218
+ * @example Template usage
219
+ * Compute the link in the component:
220
+ * ```ts
221
+ * readonly link = toRoute('/users/[id]', { params: { id: '42' } });
222
+ * ```
223
+ *
224
+ * ```html
225
+ * <a [routerLink]="link.path" [queryParams]="link.queryParams" [fragment]="link.fragment">
226
+ * ```
227
+ */
228
+ export declare function toRoute<P extends AnalogRoutePath>(path: P, ...args: RoutePathArgs<P>): RouteLinkResult;
229
+ /**
230
+ * Internal: builds a `RouteLinkResult` from path and options.
231
+ * Exported for direct use in tests (avoids generic constraints).
232
+ */
233
+ export declare function buildRouteLink(path: string, options?: RoutePathOptionsBase): RouteLinkResult;
234
+ /** Internal URL serialization for programmatic navigation. */
235
+ export declare function buildUrl(path: string, options?: RoutePathOptionsBase): string;
236
+ /** Internal: resolves `.` and `..` segments in `to` against the `from` route path. */
237
+ export declare function resolveRoutePath(from: string, to: string): string;
238
+ /**
239
+ * Internal: resolves `target` against the `from` route path. Params in the
240
+ * leading segments shared with `from` default to the `current` values.
241
+ */
242
+ export declare function resolveScopedRoute(from: string, target: string, current: Record<string, unknown>, options?: RoutePathOptionsBase): {
243
+ path: string;
244
+ options: RoutePathOptionsBase;
245
+ };
246
+ export {};
@@ -1,7 +1,7 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { QueryClient } from '@tanstack/angular-query-experimental';
3
3
  import type { DehydratedState } from '@tanstack/angular-query-experimental';
4
- import type { H3Event, H3EventContext } from 'nitro/h3';
4
+ import type { H3Event, H3EventContext } from 'h3';
5
5
  import type { $Fetch } from 'ofetch';
6
6
  import { type PageLoadContext } from '../../../server/actions/src/index.js';
7
7
  export { ANALOG_QUERIES_KEY } from '../../src/constants.js';
@@ -1,140 +0,0 @@
1
- import { InjectionToken } from '@angular/core';
2
- import type { RouterFeatures } from '@angular/router';
3
- /**
4
- * Configuration for experimental typed router features.
5
- *
6
- * Inspired by TanStack Router's type-safe navigation system where
7
- * routes are registered globally and all navigation/hooks are typed
8
- * against the route tree.
9
- *
10
- * @experimental
11
- */
12
- export interface TypedRouterOptions {
13
- /**
14
- * When true, logs warnings in development when navigating to
15
- * routes with params that don't match the generated route table.
16
- *
17
- * Similar to TanStack Router's strict mode where `useParams()`
18
- * without a `from` constraint returns a union of all possible params.
19
- *
20
- * @default false
21
- */
22
- strictRouteParams?: boolean;
23
- }
24
- /**
25
- * Configuration for experimental loader caching.
26
- *
27
- * Inspired by TanStack Router's built-in data caching where route
28
- * loaders automatically cache results and support stale-while-revalidate.
29
- *
30
- * @experimental
31
- */
32
- export interface LoaderCacheOptions {
33
- /**
34
- * Time in milliseconds before loader data is considered stale.
35
- * While data is fresh, navigating back to the route uses cached
36
- * data without re-invoking the server load function.
37
- *
38
- * Mirrors TanStack Router's `defaultStaleTime` option on `createRouter()`.
39
- *
40
- * @default 0 (always re-fetch)
41
- */
42
- defaultStaleTime?: number;
43
- /**
44
- * Time in milliseconds to retain unused loader data in cache
45
- * after leaving a route. After this period the cached entry is
46
- * garbage-collected.
47
- *
48
- * Mirrors TanStack Router's `defaultGcTime` (default 30 min).
49
- *
50
- * @default 300_000 (5 minutes)
51
- */
52
- defaultGcTime?: number;
53
- /**
54
- * Delay in milliseconds before showing a pending/loading indicator
55
- * during route transitions. Prevents flash-of-loading-state for
56
- * fast navigations.
57
- *
58
- * Mirrors TanStack Router's `defaultPendingMs`.
59
- *
60
- * @default 0 (show immediately)
61
- */
62
- defaultPendingMs?: number;
63
- }
64
- /** @experimental */
65
- export declare const EXPERIMENTAL_TYPED_ROUTER: InjectionToken<TypedRouterOptions>;
66
- /** @experimental */
67
- export declare const EXPERIMENTAL_ROUTE_CONTEXT: InjectionToken<Record<string, unknown>>;
68
- /** @experimental */
69
- export declare const EXPERIMENTAL_LOADER_CACHE: InjectionToken<LoaderCacheOptions>;
70
- /**
71
- * Enables experimental typed router features.
72
- *
73
- * When active, `routePath()`, `injectNavigate()`, `injectParams()`,
74
- * and `injectQuery()` will enforce route table constraints and
75
- * optionally log warnings in strict mode.
76
- *
77
- * Inspired by TanStack Router's `Register` interface and strict type
78
- * checking across the entire navigation surface.
79
- *
80
- * @example
81
- * ```ts
82
- * provideFileRouter(
83
- * withTypedRouter({ strictRouteParams: true }),
84
- * )
85
- * ```
86
- *
87
- * @experimental
88
- */
89
- export declare function withTypedRouter(options?: TypedRouterOptions): RouterFeatures;
90
- /**
91
- * Provides root-level route context available to all route loaders
92
- * and components via `injectRouteContext()`.
93
- *
94
- * Inspired by TanStack Router's `createRootRouteWithContext<T>()` where
95
- * a typed context object is required at router creation and automatically
96
- * available in every route's `beforeLoad` and `loader`.
97
- *
98
- * In Angular terms, this creates a DI token that server-side load
99
- * functions and components can inject to access shared services
100
- * without importing them individually.
101
- *
102
- * @example
103
- * ```ts
104
- * // app.config.ts
105
- * provideFileRouter(
106
- * withRouteContext({
107
- * auth: inject(AuthService),
108
- * db: inject(DatabaseService),
109
- * }),
110
- * )
111
- *
112
- * // In a component
113
- * const ctx = injectRouteContext<{ auth: AuthService; db: DatabaseService }>();
114
- * ```
115
- *
116
- * @experimental
117
- */
118
- export declare function withRouteContext<T extends Record<string, unknown>>(context: T): RouterFeatures;
119
- /**
120
- * Configures experimental loader caching behavior for server-loaded
121
- * route data.
122
- *
123
- * Inspired by TanStack Router's built-in cache where `createRouter()`
124
- * accepts `defaultStaleTime` and `defaultGcTime` to control when
125
- * loaders re-execute and when cached data is discarded.
126
- *
127
- * @example
128
- * ```ts
129
- * provideFileRouter(
130
- * withLoaderCaching({
131
- * defaultStaleTime: 30_000, // 30s before re-fetch
132
- * defaultGcTime: 300_000, // 5min cache retention
133
- * defaultPendingMs: 200, // 200ms loading delay
134
- * }),
135
- * )
136
- * ```
137
- *
138
- * @experimental
139
- */
140
- export declare function withLoaderCaching(options?: LoaderCacheOptions): RouterFeatures;
@@ -1,32 +0,0 @@
1
- /**
2
- * Injects the root route context provided via `withRouteContext()`.
3
- *
4
- * Inspired by TanStack Router's context inheritance where
5
- * `createRootRouteWithContext<T>()` makes a typed context available
6
- * to every route's `beforeLoad` and `loader` callbacks.
7
- *
8
- * In Angular, this uses DI under the hood — `withRouteContext(ctx)`
9
- * provides the value, and `injectRouteContext<T>()` retrieves it
10
- * with the expected type.
11
- *
12
- * @example
13
- * ```ts
14
- * // app.config.ts
15
- * provideFileRouter(
16
- * withRouteContext({
17
- * auth: inject(AuthService),
18
- * analytics: inject(AnalyticsService),
19
- * }),
20
- * )
21
- *
22
- * // any-page.page.ts
23
- * const ctx = injectRouteContext<{
24
- * auth: AuthService;
25
- * analytics: AnalyticsService;
26
- * }>();
27
- * ctx.analytics.trackPageView();
28
- * ```
29
- *
30
- * @experimental
31
- */
32
- export declare function injectRouteContext<T extends Record<string, unknown> = Record<string, unknown>>(): T;
@@ -1,124 +0,0 @@
1
- /**
2
- * Typed route path utilities for Analog.
3
- *
4
- * This module provides:
5
- * - The `AnalogRouteTable` base interface (augmented by generated code)
6
- * - The `AnalogRoutePath` union type
7
- * - The `routePath()` URL builder function
8
- *
9
- * No Angular dependencies — can be used in any context.
10
- */
11
- /**
12
- * Base interface for the typed route table.
13
- *
14
- * This interface is augmented by generated code in `src/routeTree.gen.ts`.
15
- * When no routes are generated, it is empty and `AnalogRoutePath` falls
16
- * back to `string`.
17
- */
18
- export interface AnalogRouteTable {
19
- }
20
- /**
21
- * Union of all valid route paths.
22
- *
23
- * When routes are generated, this is a string literal union.
24
- * When no routes are generated, this falls back to `string`.
25
- */
26
- export type AnalogRoutePath = keyof AnalogRouteTable extends never ? string : Extract<keyof AnalogRouteTable, string>;
27
- /**
28
- * Options for building a route URL.
29
- */
30
- export interface RoutePathOptionsBase {
31
- params?: Record<string, string | string[] | undefined>;
32
- query?: Record<string, string | string[] | undefined>;
33
- hash?: string;
34
- }
35
- /**
36
- * Extracts the validated output type for route params.
37
- *
38
- * When a route exports `routeParamsSchema`, this resolves to the schema's
39
- * output type (e.g., `{ id: number }` after coercion).
40
- * When no schema exists, this is the same as the navigation param type.
41
- */
42
- export type RouteParamsOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
43
- paramsOutput: infer O;
44
- } ? O : AnalogRouteTable[P] extends {
45
- params: infer Params;
46
- } ? Params : Record<string, unknown> : Record<string, unknown>;
47
- /**
48
- * Extracts the validated output type for route query params.
49
- */
50
- export type RouteQueryOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
51
- queryOutput: infer O;
52
- } ? O : Record<string, string | string[] | undefined> : Record<string, string | string[] | undefined>;
53
- type RequiredRouteParamKeys<Params> = Params extends Record<string, never> ? never : {
54
- [K in keyof Params]-?: Record<string, never> extends Pick<Params, K> ? never : K;
55
- }[keyof Params];
56
- type HasRequiredRouteParams<Params> = [RequiredRouteParamKeys<Params>] extends [
57
- never
58
- ] ? false : true;
59
- /**
60
- * Typed options that infer params from the route table when available.
61
- */
62
- export type RoutePathOptions<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
63
- params: infer Params;
64
- } ? Params extends Record<string, never> ? {
65
- query?: RouteQueryOutput<P>;
66
- hash?: string;
67
- } : HasRequiredRouteParams<Params> extends true ? {
68
- params: Params;
69
- query?: RouteQueryOutput<P>;
70
- hash?: string;
71
- } : {
72
- params?: Params;
73
- query?: RouteQueryOutput<P>;
74
- hash?: string;
75
- } : RoutePathOptionsBase : RoutePathOptionsBase;
76
- /**
77
- * Conditional args: require options when the route has params.
78
- */
79
- export type RoutePathArgs<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
80
- params: infer Params;
81
- } ? Params extends Record<string, never> ? [options?: RoutePathOptions<P>] : HasRequiredRouteParams<Params> extends true ? [options: RoutePathOptions<P>] : [options?: RoutePathOptions<P>] : [options?: RoutePathOptionsBase] : [options?: RoutePathOptionsBase];
82
- /**
83
- * Result of `routePath()` — contains properties that map directly
84
- * to Angular's `[routerLink]`, `[queryParams]`, and `[fragment]` inputs.
85
- */
86
- export interface RouteLinkResult {
87
- path: string;
88
- queryParams: Record<string, string | string[]> | null;
89
- fragment: string | undefined;
90
- }
91
- /**
92
- * Builds a typed route link object from a route path pattern and options.
93
- *
94
- * The returned object separates path, query params, and fragment for
95
- * direct use with Angular's routerLink directive inputs.
96
- *
97
- * @example
98
- * routePath('/about')
99
- * // → { path: '/about', queryParams: null, fragment: undefined }
100
- *
101
- * routePath('/users/[id]', { params: { id: '42' } })
102
- * // → { path: '/users/42', queryParams: null, fragment: undefined }
103
- *
104
- * routePath('/users/[id]', { params: { id: '42' }, query: { tab: 'settings' }, hash: 'bio' })
105
- * // → { path: '/users/42', queryParams: { tab: 'settings' }, fragment: 'bio' }
106
- *
107
- * @example Template usage
108
- * ```html
109
- * @let link = routePath('/users/[id]', { params: { id: userId } });
110
- * <a [routerLink]="link.path" [queryParams]="link.queryParams" [fragment]="link.fragment">
111
- * ```
112
- */
113
- export declare function routePath<P extends AnalogRoutePath>(path: P, ...args: RoutePathArgs<P>): RouteLinkResult;
114
- /**
115
- * Internal: builds a `RouteLinkResult` from path and options.
116
- * Exported for direct use in tests (avoids generic constraints).
117
- */
118
- export declare function buildRouteLink(path: string, options?: RoutePathOptionsBase): RouteLinkResult;
119
- /**
120
- * Internal URL builder. Separated from `routePath` so it can be
121
- * used without generic constraints (e.g., in `injectNavigate`).
122
- */
123
- export declare function buildUrl(path: string, options?: RoutePathOptionsBase): string;
124
- export {};