@kitbag/router 0.7.1 → 0.8.0

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.
package/README.md CHANGED
@@ -100,7 +100,7 @@ const settings = createRoute({
100
100
 
101
101
  const router = useRouter([user, profile, settings])
102
102
 
103
- router.push('user.settings')
103
+ router.push('settings')
104
104
  ```
105
105
 
106
106
  The push method also accepts a plain string if you know the URL you want to go to.
@@ -110,7 +110,7 @@ router.push('/user/settings')
110
110
  router.push('https://github.com/kitbagjs/router')
111
111
  ```
112
112
 
113
- This `source` argument is type safe, expecting either a Url or a valid route "key". Url is any string that starts with "http", "https", or a forward slash "/". Route key is a string of route names joined by a period `.`. Additionally if using the route key, push will require params be passed in if there are any.
113
+ This `source` argument is type safe, expecting either a [`Url`](/api/types/Url) or a valid route [`name`](/api/types/Route#name). URL is any string that starts with "http", "https", or a forward slash "/". Additionally if using the route name, push will require params be passed in if there are any.
114
114
 
115
115
  ## Update
116
116
 
@@ -18,6 +18,10 @@ declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
18
18
 
19
19
  declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T;
20
20
 
21
+ declare type __VLS_Prettify<T> = {
22
+ [K in keyof T]: T[K];
23
+ } & {};
24
+
21
25
  declare type __VLS_TypePropsToRuntimeProps<T> = {
22
26
  [K in keyof T]-?: {} extends Pick<T, K> ? {
23
27
  type: PropType<__VLS_NonUndefinedable<T[K]>>;
@@ -36,6 +40,12 @@ declare type __VLS_TypePropsToRuntimeProps_2<T> = {
36
40
  };
37
41
  };
38
42
 
43
+ declare type __VLS_WithDefaults<P, D> = {
44
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
45
+ default: D[K];
46
+ }> : P[K];
47
+ };
48
+
39
49
  declare type __VLS_WithTemplateSlots<T, S> = T & {
40
50
  new (): {
41
51
  $slots: S;
@@ -121,8 +131,6 @@ declare const builtInRejections: ['NotFound'];
121
131
 
122
132
  declare type BuiltInRejectionType = typeof builtInRejections[number];
123
133
 
124
- declare type CombineKey<TParentKey extends string | undefined, TChildKey extends string | undefined> = StringHasValue<TParentKey> extends true ? StringHasValue<TChildKey> extends true ? `${TParentKey}.${TChildKey}` : TParentKey : StringHasValue<TChildKey> extends true ? TChildKey : '';
125
-
126
134
  declare type CombineMeta<TParent extends Record<string, unknown>, TChild extends Record<string, unknown>> = TParent & TChild;
127
135
 
128
136
  declare type CombinePath<TParent extends Path, TChild extends Path> = ToPath<TParent> extends {
@@ -171,9 +179,9 @@ declare type ComponentPropsGetter<TComponent extends Component> = () => MaybePro
171
179
 
172
180
  declare type Constructor = new (...args: any) => any;
173
181
 
174
- export declare function createExternalRoute<const THost extends string | Host, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined>(options: CreateRouteOptions<TName, TPath, TQuery> & WithHost<THost> & WithoutParent): Route<ToKey<TName>, ToHost<THost>, ToPath<TPath>, ToQuery<TQuery>>;
182
+ export declare function createExternalRoute<const THost extends string | Host, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined>(options: CreateRouteOptions<TName, TPath, TQuery> & WithHost<THost> & WithoutParent): Route<ToName<TName>, ToHost<THost>, ToPath<TPath>, ToQuery<TQuery>>;
175
183
 
176
- export declare function createExternalRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined>(options: CreateRouteOptions<TName, TPath, TQuery> & WithoutHost & WithParent<TParent>): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>>;
184
+ export declare function createExternalRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined>(options: CreateRouteOptions<TName, TPath, TQuery> & WithoutHost & WithParent<TParent>): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>>;
177
185
 
178
186
  export declare function createParam<TParam extends ParamWithDefault>(param: TParam): TParam;
179
187
 
@@ -181,17 +189,17 @@ export declare function createParam<TParam extends Param>(param: TParam): ParamG
181
189
 
182
190
  export declare function createParam<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
183
191
 
184
- export declare function createRoute<const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithoutParent & (WithState<TState> | WithoutState)): Route<ToKey<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
192
+ export declare function createRoute<const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
185
193
 
186
- export declare function createRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
194
+ export declare function createRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
187
195
 
188
- export declare function createRoute<TComponent extends Component, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToKey<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
196
+ export declare function createRoute<TComponent extends Component, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
189
197
 
190
- export declare function createRoute<TComponent extends Component, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
198
+ export declare function createRoute<TComponent extends Component, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
191
199
 
192
- export declare function createRoute<TComponents extends Record<string, Component>, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToKey<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
200
+ export declare function createRoute<TComponents extends Record<string, Component>, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
193
201
 
194
- export declare function createRoute<TComponents extends Record<string, Component>, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
202
+ export declare function createRoute<TComponents extends Record<string, Component>, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
195
203
 
196
204
  export declare type CreateRouteOptions<TName extends string | undefined = string | undefined, TPath extends string | Path | undefined = string | Path | undefined, TQuery extends string | Query | undefined = string | Query | undefined, TMeta extends RouteMeta = RouteMeta> = {
197
205
  /**
@@ -210,6 +218,10 @@ export declare type CreateRouteOptions<TName extends string | undefined = string
210
218
  * Represents additional metadata associated with a route, customizable via declaration merging.
211
219
  */
212
220
  meta?: TMeta;
221
+ /**
222
+ * Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch.
223
+ */
224
+ prefetch?: PrefetchConfig;
213
225
  };
214
226
 
215
227
  /**
@@ -247,8 +259,8 @@ export declare function createRouter<const T extends Routes>(routes: T, options?
247
259
  export declare function createRouter<const T extends Routes>(arrayOfRoutes: T[], options?: RouterOptions): Router<T>;
248
260
 
249
261
  /**
250
- * An error thrown when duplicate parameters are detected in a route when creating a router.
251
- * When defining routes, param names must be unique. This includes params defined in a path
262
+ * An error thrown when duplicate parameters are detected in a route.
263
+ * Param names must be unique. This includes params defined in a path
252
264
  * parent and params defined in the query.
253
265
  */
254
266
  export declare class DuplicateParamsError extends Error {
@@ -367,33 +379,33 @@ export declare function isParamWithDefault(param: Param): param is ParamWithDefa
367
379
 
368
380
  export declare function isRoute(route: unknown): route is RouterRoute;
369
381
 
370
- export declare function isRoute<TRoute extends RouterRoute, TRouteKey extends TRoute['key']>(route: TRoute, routeKey: TRouteKey, options: IsRouteOptions & {
382
+ export declare function isRoute<TRoute extends RouterRoute, TRouteName extends TRoute['name']>(route: TRoute, routeName: TRouteName, options: IsRouteOptions & {
371
383
  exact: true;
372
384
  }): route is TRoute & {
373
- key: TRouteKey;
385
+ name: TRouteName;
374
386
  };
375
387
 
376
- export declare function isRoute<TRoute extends RouterRoute, TRouteKey extends TRoute['key']>(route: TRoute, routeKey: TRouteKey, options?: IsRouteOptions): route is TRoute & {
377
- key: `${TRouteKey}${string}`;
388
+ export declare function isRoute<TRoute extends RouterRoute, TRouteName extends TRoute['name']>(route: TRoute, routeName: TRouteName, options?: IsRouteOptions): route is TRoute & {
389
+ name: `${TRouteName}${string}`;
378
390
  };
379
391
 
380
- export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options: IsRouteOptions & {
392
+ export declare function isRoute<TRouteName extends RegisteredRoutesName>(route: unknown, routeName: TRouteName, options: IsRouteOptions & {
381
393
  exact: true;
382
394
  }): route is RegisteredRouterRoute & {
383
- key: TRouteKey;
395
+ name: TRouteName;
384
396
  };
385
397
 
386
- export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options?: IsRouteOptions): route is RegisteredRouterRoute & {
387
- key: `${TRouteKey}${string}`;
398
+ export declare function isRoute<TRouteName extends RegisteredRoutesName>(route: unknown, routeName: TRouteName, options?: IsRouteOptions): route is RegisteredRouterRoute & {
399
+ name: `${TRouteName}${string}`;
388
400
  };
389
401
 
390
- export declare function isRoute(route: unknown, routeKey?: string, options?: IsRouteOptions): boolean;
402
+ export declare function isRoute(route: unknown, routeName?: string, options?: IsRouteOptions): boolean;
391
403
 
392
404
  declare type IsRouteOptions = {
393
405
  exact?: boolean;
394
406
  };
395
407
 
396
- declare type IsRouteUnnamed<T extends Route> = StringHasValue<T['key']> extends true ? false : true;
408
+ declare type IsRouteUnnamed<T extends Route> = StringHasValue<T['name']> extends true ? false : true;
397
409
 
398
410
  declare type MakeOptional<T> = {
399
411
  [P in WithOptionalProperties<T>]?: T[P];
@@ -517,6 +529,19 @@ declare type PathParamsWithParamNameExtracted<TPath extends string> = {
517
529
  [K in keyof ExtractParamsFromPathString<TPath> as ExtractParamName<K>]?: Param;
518
530
  };
519
531
 
532
+ /**
533
+ * Determines what assets are prefetched. A boolean enables or disables all prefetching.
534
+ */
535
+ declare type PrefetchConfig = boolean | PrefetchConfigOptions;
536
+
537
+ declare type PrefetchConfigOptions = {
538
+ /**
539
+ * When true any component that is wrapped in vue's defineAsyncComponent will be prefetched
540
+ * @default true
541
+ */
542
+ components?: boolean;
543
+ };
544
+
520
545
  declare type Query<TQuery extends string = string, TQueryParams extends QueryParamsWithParamNameExtracted<TQuery> = Record<string, Param | undefined>> = {
521
546
  query: TQuery;
522
547
  params: string extends TQuery ? Record<string, Param> : Identity<ExtractQueryParamsFromQueryString<TQuery, TQueryParams>>;
@@ -576,7 +601,7 @@ export declare type RegisteredRejectionType = Register extends {
576
601
  } ? TRejections[number] : never;
577
602
 
578
603
  /**
579
- * Represents the a map of all possible RouteKeys with corresponding Route registered within {@link Register}
604
+ * Represents the a map of all possible route names with corresponding Route registered within {@link Register}
580
605
  */
581
606
  export declare type RegisteredRouteMap = RoutesMap<RegisteredRoutes>;
582
607
 
@@ -610,9 +635,9 @@ export declare type RegisteredRoutes = Register extends {
610
635
  } ? TRoutes : Route[];
611
636
 
612
637
  /**
613
- * Represents the union of all possible RouteKeys registered within {@link Register}
638
+ * Represents the union of all possible route names registered within {@link Register}
614
639
  */
615
- export declare type RegisteredRoutesKey = RoutesKey<RegisteredRoutes>;
640
+ export declare type RegisteredRoutesName = RoutesName<RegisteredRoutes>;
616
641
 
617
642
  declare type RemoveLeadingQuestionMark<T extends PropertyKey> = T extends `?${infer TRest extends string}` ? TRest : T;
618
643
 
@@ -635,9 +660,9 @@ declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
635
660
  */
636
661
  matches: TRoute['matches'];
637
662
  /**
638
- * Unique identifier for the route, generated by joining route `name` by period. Key is used for routing and for matching.
663
+ * Unique identifier for the route. Name is used for routing and for matching.
639
664
  */
640
- key: TRoute['key'];
665
+ name: TRoute['name'];
641
666
  /**
642
667
  * Accessor for query string values from user in the current browser location.
643
668
  */
@@ -659,11 +684,11 @@ declare type ResolvedRouteQuery = {
659
684
 
660
685
  /**
661
686
  * Represents the structure of a route within the application. Return value of `createRoute`
662
- * @template TKey - Represents the unique key identifying the route, typically a string.
687
+ * @template TName - Represents the unique name identifying the route, typically a string.
663
688
  * @template TPath - The type or structure of the route's path.
664
689
  * @template TQuery - The type or structure of the query parameters associated with the route.
665
690
  */
666
- export declare type Route<TKey extends string = string, THost extends Host = Host, TPath extends Path = Path, TQuery extends Query = Query, TMeta extends RouteMeta = RouteMeta, TState extends Record<string, Param> = Record<string, Param>> = {
691
+ export declare type Route<TName extends string = string, THost extends Host = Host, TPath extends Path = Path, TQuery extends Query = Query, TMeta extends RouteMeta = RouteMeta, TState extends Record<string, Param> = Record<string, Param>> = {
667
692
  /**
668
693
  * The specific route properties that were matched in the current route.
669
694
  */
@@ -674,9 +699,9 @@ export declare type Route<TKey extends string = string, THost extends Host = Hos
674
699
  */
675
700
  matches: CreateRouteOptionsMatched[];
676
701
  /**
677
- * Unique identifier for the route, generated by joining route `name` by period. Key is used for routing and for matching.
702
+ * Unique identifier for the route. Name is used for routing and for matching.
678
703
  */
679
- key: TKey;
704
+ name: TName;
680
705
  /**
681
706
  * Represents the host for this route. Used for external routes.
682
707
  */
@@ -697,10 +722,14 @@ export declare type Route<TKey extends string = string, THost extends Host = Hos
697
722
  * Represents the schema of the route state, combined with any parents.
698
723
  */
699
724
  state: TState;
700
- depth: number;
725
+ /**
726
+ * Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch.
727
+ */
728
+ prefetch?: PrefetchConfig;
729
+ /* Excluded from this release type: depth */
701
730
  };
702
731
 
703
- declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesKey<TRoutes>> = RoutesMap<TRoutes>[TKey];
732
+ declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesName<TRoutes>> = RoutesMap<TRoutes>[TKey];
704
733
 
705
734
  /**
706
735
  * Generic type representing a route hook, which can be either before or after a route change.
@@ -853,24 +882,30 @@ export declare type Router<TRoutes extends Routes = any> = Plugin_2 & {
853
882
  * Given a URL, returns true if host does not match host stored on router instance
854
883
  */
855
884
  isExternal: (url: string) => boolean;
885
+ /**
886
+ * Determines what assets are prefetched.
887
+ */
888
+ prefetch?: PrefetchConfig;
856
889
  };
857
890
 
858
891
  declare type RouterFind<TRoutes extends Routes> = {
859
- <TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterFindArgs<TRoutes, TSource>): ResolvedRoute | undefined;
860
- (source: Url): ResolvedRoute | undefined;
892
+ <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterFindArgs<TRoutes, TSource>): ResolvedRoute | undefined;
893
+ (url: Url): ResolvedRoute | undefined;
861
894
  };
862
895
 
863
- declare type RouterFindArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams] : [params: TParams];
896
+ declare type RouterFindArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams] : [params: TParams];
864
897
 
865
898
  declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
866
899
 
867
900
  export declare const routerInjectionKey: InjectionKey<RegisteredRouter>;
868
901
 
869
- export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent<__VLS_TypePropsToRuntimeProps_2<{
870
- to: Url | ToCallback;
871
- } & RouterPushOptions>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_2<{
872
- to: Url | ToCallback;
873
- } & RouterPushOptions>>>, {}, {}>, Readonly<{
902
+ export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps_2<RouterLinkProps & RouterPushOptions>, {
903
+ prefetch: undefined;
904
+ }>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps_2<RouterLinkProps & RouterPushOptions>, {
905
+ prefetch: undefined;
906
+ }>>>, {
907
+ prefetch: PrefetchConfig;
908
+ }, {}>, Readonly<{
874
909
  default?: ((props: {
875
910
  resolved: string;
876
911
  isMatch: boolean;
@@ -886,6 +921,17 @@ to: Url | ToCallback;
886
921
  }) => unknown) | undefined;
887
922
  }>;
888
923
 
924
+ declare type RouterLinkProps = {
925
+ /**
926
+ * The url string to navigate to or a callback that returns a url string
927
+ */
928
+ to: Url | ToCallback;
929
+ /**
930
+ * Determines what assets are prefetched when router-link is rendered for this route. Overrides route level prefetch.
931
+ */
932
+ prefetch?: PrefetchConfig;
933
+ };
934
+
889
935
  /**
890
936
  * An error thrown when an attempt is made to use routing functionality before the router has been installed.
891
937
  */
@@ -914,14 +960,18 @@ export declare type RouterOptions = {
914
960
  * For example having `base` of `/foo` would assume all routes should start with `your.domain.com/foo`.
915
961
  */
916
962
  base?: string;
963
+ /**
964
+ * Determines what assets are prefetched when router-link is rendered for a specific route
965
+ */
966
+ prefetch?: PrefetchConfig;
917
967
  } & RouterRejectionComponents;
918
968
 
919
969
  declare type RouterPush<TRoutes extends Routes = any> = {
920
- <TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterPushArgs<TRoutes, TSource>): Promise<void>;
921
- (source: Url, options?: RouterPushOptions): Promise<void>;
970
+ <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterPushArgs<TRoutes, TSource>): Promise<void>;
971
+ (url: Url, options?: RouterPushOptions): Promise<void>;
922
972
  };
923
973
 
924
- declare type RouterPushArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>> = AllPropertiesAreOptional<RouteParamsByKey<TRoutes, TSource>> extends true ? [params?: RouteParamsByKey<TRoutes, TSource>, options?: RouterPushOptions<RouteStateByKey<TRoutes, TSource>>] : [params: RouteParamsByKey<TRoutes, TSource>, options?: RouterPushOptions<RouteStateByKey<TRoutes, TSource>>];
974
+ declare type RouterPushArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>> = AllPropertiesAreOptional<RouteParamsByKey<TRoutes, TSource>> extends true ? [params?: RouteParamsByKey<TRoutes, TSource>, options?: RouterPushOptions<RouteStateByName<TRoutes, TSource>>] : [params: RouteParamsByKey<TRoutes, TSource>, options?: RouterPushOptions<RouteStateByName<TRoutes, TSource>>];
925
975
 
926
976
  declare type RouterPushOptions<TState = unknown> = {
927
977
  query?: Record<string, string>;
@@ -945,11 +995,11 @@ export declare const routerRejectionKey: InjectionKey<RouterRejection>;
945
995
  declare type RouterRejectionType = BuiltInRejectionType | RegisteredRejectionType;
946
996
 
947
997
  declare type RouterReplace<TRoutes extends Routes> = {
948
- <TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
949
- (source: Url, options?: RouterReplaceOptions): Promise<void>;
998
+ <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
999
+ (url: Url, options?: RouterReplaceOptions): Promise<void>;
950
1000
  };
951
1001
 
952
- declare type RouterReplaceArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterReplaceOptions<RouteStateByKey<TRoutes, TSource>>] : [params: TParams, options?: RouterReplaceOptions<RouteStateByKey<TRoutes, TSource>>];
1002
+ declare type RouterReplaceArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterReplaceOptions<RouteStateByName<TRoutes, TSource>>] : [params: TParams, options?: RouterReplaceOptions<RouteStateByName<TRoutes, TSource>>];
953
1003
 
954
1004
  declare type RouterReplaceOptions<TState = unknown> = {
955
1005
  query?: Record<string, string>;
@@ -957,18 +1007,18 @@ declare type RouterReplaceOptions<TState = unknown> = {
957
1007
  };
958
1008
 
959
1009
  declare type RouterResolve<TRoutes extends Routes> = {
960
- <TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterResolveArgs<TRoutes, TSource>): string;
961
- (source: Url, options?: RouterResolveOptions): string;
1010
+ <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterResolveArgs<TRoutes, TSource>): string;
1011
+ (url: Url, options?: RouterResolveOptions): string;
962
1012
  };
963
1013
 
964
- declare type RouterResolveArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterResolveOptions] : [params: TParams, options?: RouterResolveOptions];
1014
+ declare type RouterResolveArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterResolveOptions] : [params: TParams, options?: RouterResolveOptions];
965
1015
 
966
1016
  declare type RouterResolveOptions = {
967
1017
  query?: Record<string, string>;
968
1018
  };
969
1019
 
970
1020
  declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = Readonly<{
971
- key: TRoute['key'];
1021
+ name: TRoute['name'];
972
1022
  matched: TRoute['matched'];
973
1023
  matches: TRoute['matches'];
974
1024
  state: TRoute['state'];
@@ -991,7 +1041,7 @@ name?: string | undefined;
991
1041
  }>>>, {}, {}>, Readonly<{
992
1042
  default?: ((props: {
993
1043
  route: Readonly<{
994
- key: string;
1044
+ name: string;
995
1045
  matched: CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
996
1046
  meta: Record<string, unknown>;
997
1047
  };
@@ -1008,7 +1058,7 @@ name?: string | undefined;
1008
1058
  [x: number]: any;
1009
1059
  }>;
1010
1060
  update: {
1011
- (key: string, value: unknown, options?: RouterPushOptions | undefined): Promise<void>;
1061
+ (paramName: string, paramValue: unknown, options?: RouterPushOptions | undefined): Promise<void>;
1012
1062
  (params: Partial<{
1013
1063
  [x: string]: any;
1014
1064
  [x: number]: any;
@@ -1026,7 +1076,7 @@ name?: string | undefined;
1026
1076
  }> & {
1027
1077
  default?: ((props: {
1028
1078
  route: Readonly<{
1029
- key: string;
1079
+ name: string;
1030
1080
  matched: CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
1031
1081
  meta: Record<string, unknown>;
1032
1082
  };
@@ -1043,7 +1093,7 @@ name?: string | undefined;
1043
1093
  [x: number]: any;
1044
1094
  }>;
1045
1095
  update: {
1046
- (key: string, value: unknown, options?: RouterPushOptions | undefined): Promise<void>;
1096
+ (paramName: string, paramValue: unknown, options?: RouterPushOptions | undefined): Promise<void>;
1047
1097
  (params: Partial<{
1048
1098
  [x: string]: any;
1049
1099
  [x: number]: any;
@@ -1065,19 +1115,19 @@ name?: string | undefined;
1065
1115
  */
1066
1116
  export declare type Routes = Readonly<Route[]>;
1067
1117
 
1068
- declare type RoutesKey<TRoutes extends Routes> = string & keyof RoutesMap<TRoutes>;
1069
-
1070
1118
  declare type RoutesMap<TRoutes extends Routes = []> = {
1071
- [K in TRoutes[number] as AsNamedRoute<K>['key']]: AsNamedRoute<K>;
1119
+ [K in TRoutes[number] as AsNamedRoute<K>['name']]: AsNamedRoute<K>;
1072
1120
  };
1073
1121
 
1074
- declare type RouteStateByKey<TRoutes extends Routes, TKey extends string> = ExtractStateParams<RouteGetByKey<TRoutes, TKey>>;
1122
+ declare type RoutesName<TRoutes extends Routes> = string & keyof RoutesMap<TRoutes>;
1123
+
1124
+ declare type RouteStateByName<TRoutes extends Routes, TName extends string> = ExtractStateParams<RouteGetByKey<TRoutes, TName>>;
1075
1125
 
1076
1126
  declare type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = ResolvedRoute extends TRoute ? {
1077
- (key: string, value: unknown, options?: RouterPushOptions): Promise<void>;
1127
+ (paramName: string, paramValue: unknown, options?: RouterPushOptions): Promise<void>;
1078
1128
  (params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
1079
1129
  } : {
1080
- <TKey extends keyof TRoute['params']>(key: TKey, value: TRoute['params'][TKey], options?: RouterPushOptions): Promise<void>;
1130
+ <TParamName extends keyof TRoute['params']>(paramName: TParamName, paramValue: TRoute['params'][TParamName], options?: RouterPushOptions): Promise<void>;
1081
1131
  (params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
1082
1132
  };
1083
1133
 
@@ -1087,7 +1137,7 @@ declare type ToCallback = (resolve: RegisteredRouter['resolve']) => string;
1087
1137
 
1088
1138
  declare type ToHost<T extends string | Host | undefined> = T extends string ? Host<T, {}> : T extends undefined ? Host<'', {}> : unknown extends T ? Host<'', {}> : T;
1089
1139
 
1090
- declare type ToKey<T extends string | undefined> = T extends string ? T : '';
1140
+ declare type ToName<T extends string | undefined> = T extends string ? T : '';
1091
1141
 
1092
1142
  declare type ToPath<T extends string | Path | undefined> = T extends string ? Path<T, {}> : T extends undefined ? Path<'', {}> : unknown extends T ? Path<'', {}> : T;
1093
1143
 
@@ -1127,17 +1177,21 @@ export declare type UseLink = {
1127
1177
  * or resolved URL to discover route details. Also exports some useful context about routes relationship to current URL and convenience methods
1128
1178
  * for navigating.
1129
1179
  *
1130
- * @param source - The key of the route or the URL value.
1131
- * @param params - If providing route key, this argument will expect corresponding params.
1180
+ * @param source - The name of the route or the URL value.
1181
+ * @param params - If providing route name, this argument will expect corresponding params.
1132
1182
  * @param options - {@link RouterResolveOptions}Same options as router resolve.
1133
1183
  * @returns {UseLink} Reactive context values for as well as navigation methods.
1134
1184
  *
1135
1185
  */
1136
- export declare function useLink<TRouteKey extends RegisteredRoutesKey>(routeKey: MaybeRefOrGetter<TRouteKey>, ...args: UseLinkArgs<TRouteKey>): UseLink;
1186
+ export declare function useLink<TRouteKey extends RegisteredRoutesName>(name: MaybeRefOrGetter<TRouteKey>, ...args: UseLinkArgs<TRouteKey>): UseLink;
1187
+
1188
+ export declare function useLink(url: MaybeRefOrGetter<Url>, options?: MaybeRefOrGetter<UseLinkOptions>): UseLink;
1137
1189
 
1138
- export declare function useLink(url: MaybeRefOrGetter<Url>): UseLink;
1190
+ declare type UseLinkArgs<TSource extends RegisteredRoutesName, TParams = RouteParamsByKey<RegisteredRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<UseLinkOptions>] : [params: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<UseLinkOptions>];
1139
1191
 
1140
- declare type UseLinkArgs<TSource extends RegisteredRoutesKey, TParams = RouteParamsByKey<RegisteredRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<RouterResolveOptions>] : [params: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<RouterResolveOptions>];
1192
+ export declare type UseLinkOptions = RouterResolveOptions & {
1193
+ prefetch?: PrefetchConfig;
1194
+ };
1141
1195
 
1142
1196
  /**
1143
1197
  * A composition to access the router's rejection state.
@@ -1150,29 +1204,29 @@ declare type UseLinkArgs<TSource extends RegisteredRoutesKey, TParams = RoutePar
1150
1204
  export declare function useRejection(): RouterRejection;
1151
1205
 
1152
1206
  /**
1153
- * A composition to access the current route or verify a specific route key within a Vue component.
1207
+ * A composition to access the current route or verify a specific route name within a Vue component.
1154
1208
  * This function provides two overloads:
1155
1209
  * 1. When called without arguments, it returns the current route from the router without types.
1156
- * 2. When called with a route key, it checks if the current active route includes the specified route key.
1210
+ * 2. When called with a route name, it checks if the current active route includes the specified route name.
1157
1211
  *
1158
- * @template TRouteKey - A string type that should match route key of RegisteredRouteMap, ensuring the route key exists.
1159
- * @param routeKey - Optional. The key of the route to validate against the current active routes.
1160
- * @returns The current router route. If a route key is provided, it validates the route key first.
1161
- * @throws {UseRouteInvalidError} Throws an error if the provided route key is not valid or does not match the current route.
1212
+ * @template TRouteName - A string type that should match route name of RegisteredRouteMap, ensuring the route name exists.
1213
+ * @param routeName - Optional. The name of the route to validate against the current active routes.
1214
+ * @returns The current router route. If a route name is provided, it validates the route name first.
1215
+ * @throws {UseRouteInvalidError} Throws an error if the provided route name is not valid or does not match the current route.
1162
1216
  *
1163
- * The function also sets up a reactive watcher on the route object from the router to continually check the validity of the route key
1217
+ * The function also sets up a reactive watcher on the route object from the router to continually check the validity of the route name
1164
1218
  * if provided, throwing an error if the validation fails at any point during the component's lifecycle.
1165
1219
  */
1166
1220
  export declare function useRoute(): RegisteredRouterRoute;
1167
1221
 
1168
- export declare function useRoute<TRouteKey extends RegisteredRoutesKey>(routeKey: TRouteKey, options: IsRouteOptions & {
1222
+ export declare function useRoute<TRouteName extends RegisteredRoutesName>(routeName: TRouteName, options: IsRouteOptions & {
1169
1223
  exact: true;
1170
1224
  }): RegisteredRouterRoute & {
1171
- key: TRouteKey;
1225
+ name: TRouteName;
1172
1226
  };
1173
1227
 
1174
- export declare function useRoute<TRouteKey extends RegisteredRoutesKey>(routeKey: TRouteKey, options?: IsRouteOptions): RegisteredRouterRoute & {
1175
- key: `${TRouteKey}${string}`;
1228
+ export declare function useRoute<TRouteName extends RegisteredRoutesName>(routeName: TRouteName, options?: IsRouteOptions): RegisteredRouterRoute & {
1229
+ name: `${TRouteName}${string}`;
1176
1230
  };
1177
1231
 
1178
1232
  /**