@kitbag/router 0.13.4 → 0.14.1

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.
@@ -253,7 +253,7 @@ declare type CreateRouteOptionsMatched<TName extends string | undefined = string
253
253
  * export const routes = [
254
254
  * createRoute({ name: 'home', path: '/', component: Home }),
255
255
  * createRoute({ name: 'path', path: '/about', component: About }),
256
- * ]
256
+ * ] as const
257
257
  *
258
258
  * const router = createRouter(routes)
259
259
  * ```
@@ -750,11 +750,11 @@ export declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
750
750
  /**
751
751
  * Accessor for query string values from user in the current browser location.
752
752
  */
753
- query: ResolvedRouteQuery;
753
+ query: URLSearchParams;
754
754
  /**
755
755
  * Hash value of the route.
756
756
  */
757
- hash?: string;
757
+ hash: string;
758
758
  /**
759
759
  * Key value pair for route params, values will be the user provided value from current browser location.
760
760
  */
@@ -763,22 +763,12 @@ export declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
763
763
  * Type for additional data intended to be stored in history state.
764
764
  */
765
765
  state: ExtractRouteStateParamsAsOptional<TRoute['state']>;
766
+ /**
767
+ * String value of the resolved URL.
768
+ */
769
+ href: Url;
766
770
  }>;
767
771
 
768
- declare type ResolvedRouteQuery = {
769
- append: URLSearchParams['append'];
770
- delete: URLSearchParams['delete'];
771
- entries: URLSearchParams['entries'];
772
- forEach: URLSearchParams['forEach'];
773
- get: URLSearchParams['get'];
774
- getAll: URLSearchParams['getAll'];
775
- has: URLSearchParams['has'];
776
- keys: URLSearchParams['keys'];
777
- set: URLSearchParams['set'];
778
- toString: URLSearchParams['toString'];
779
- values: URLSearchParams['values'];
780
- };
781
-
782
772
  /**
783
773
  * Represents the structure of a route within the application. Return value of `createRoute`
784
774
  * @template TName - Represents the unique name identifying the route, typically a string.
@@ -882,9 +872,13 @@ export declare type Router<TRoutes extends Routes = any, __TOptions extends Rout
882
872
  */
883
873
  route: RouterRoutes<TRoutes>;
884
874
  /**
885
- * Resolves a URL to a route object.
875
+ * Creates a ResolvedRoute record for a given route name and params.
886
876
  */
887
877
  resolve: RouterResolve<TRoutes>;
878
+ /**
879
+ * Creates a ResolvedRoute record for a given URL.
880
+ */
881
+ find: (url: string, options?: RouterResolveOptions) => ResolvedRoute | undefined;
888
882
  /**
889
883
  * Navigates to a specified path or route object in the history stack, adding a new entry.
890
884
  */
@@ -893,10 +887,6 @@ export declare type Router<TRoutes extends Routes = any, __TOptions extends Rout
893
887
  * Replaces the current entry in the history stack with a new one.
894
888
  */
895
889
  replace: RouterReplace<TRoutes>;
896
- /**
897
- * Finds a route object based on the provided lookup parameters.
898
- */
899
- find: RouterFind<TRoutes>;
900
890
  /**
901
891
  * Handles route rejection based on a specified rejection type.
902
892
  */
@@ -955,13 +945,6 @@ export declare type Router<TRoutes extends Routes = any, __TOptions extends Rout
955
945
  start: () => Promise<void>;
956
946
  };
957
947
 
958
- declare type RouterFind<TRoutes extends Routes> = {
959
- <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterFindArgs<TRoutes, TSource>): ResolvedRoute | undefined;
960
- (url: Url): ResolvedRoute | undefined;
961
- };
962
-
963
- declare type RouterFindArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams] : [params: TParams];
964
-
965
948
  declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
966
949
 
967
950
  /**
@@ -971,7 +954,7 @@ export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent< {
971
954
  /**
972
955
  * The url string to navigate to or a callback that returns a url string
973
956
  */
974
- to: Url | ((resolve: RegisteredRouter["resolve"]) => Url);
957
+ to: Url | ResolvedRoute | ToCallback;
975
958
  /**
976
959
  * Determines what assets are prefetched when router-link is rendered for this route. Overrides route level prefetch.
977
960
  */
@@ -980,23 +963,23 @@ prefetch?: PrefetchConfig;
980
963
  /**
981
964
  * The url string to navigate to or a callback that returns a url string
982
965
  */
983
- to: Url | ((resolve: RegisteredRouter["resolve"]) => Url);
966
+ to: Url | ResolvedRoute | ToCallback;
984
967
  /**
985
968
  * Determines what assets are prefetched when router-link is rendered for this route. Overrides route level prefetch.
986
969
  */
987
970
  prefetch?: PrefetchConfig;
988
- } & RouterPushOptions & {}>, {
971
+ } & RouterPushOptions> & Readonly<{}>, {
989
972
  prefetch: PrefetchConfig;
990
- }, {}, {}, {}, string, ComponentProvideOptions, false, {}>, Readonly<{
973
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>, Readonly<{
991
974
  default?: (props: {
992
- resolved: string;
975
+ route: ResolvedRoute | undefined;
993
976
  isMatch: boolean;
994
977
  isExactMatch: boolean;
995
978
  isExternal: boolean;
996
979
  }) => unknown;
997
980
  }> & {
998
981
  default?: (props: {
999
- resolved: string;
982
+ route: ResolvedRoute | undefined;
1000
983
  isMatch: boolean;
1001
984
  isExactMatch: boolean;
1002
985
  isExternal: boolean;
@@ -1045,6 +1028,7 @@ export declare type RouterOptions = {
1045
1028
  declare type RouterPush<TRoutes extends Routes = any> = {
1046
1029
  <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterPushArgs<TRoutes, TSource>): Promise<void>;
1047
1030
  (url: Url, options?: RouterPushOptions): Promise<void>;
1031
+ (route: ResolvedRoute, options?: RouterPushOptions): Promise<void>;
1048
1032
  };
1049
1033
 
1050
1034
  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>>];
@@ -1066,9 +1050,10 @@ declare type RouterRejection = Ref<null | {
1066
1050
  declare type RouterReplace<TRoutes extends Routes> = {
1067
1051
  <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
1068
1052
  (url: Url, options?: RouterReplaceOptions): Promise<void>;
1053
+ (route: ResolvedRoute, options?: RouterReplaceOptions): Promise<void>;
1069
1054
  };
1070
1055
 
1071
- 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>>];
1056
+ declare type RouterReplaceArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>> = AllPropertiesAreOptional<RouteParamsByKey<TRoutes, TSource>> extends true ? [params?: RouteParamsByKey<TRoutes, TSource>, options?: RouterReplaceOptions<RouteStateByName<TRoutes, TSource>>] : [params: RouteParamsByKey<TRoutes, TSource>, options?: RouterReplaceOptions<RouteStateByName<TRoutes, TSource>>];
1072
1057
 
1073
1058
  declare type RouterReplaceOptions<TState = unknown> = {
1074
1059
  query?: QuerySource;
@@ -1076,16 +1061,14 @@ declare type RouterReplaceOptions<TState = unknown> = {
1076
1061
  state?: Partial<TState>;
1077
1062
  };
1078
1063
 
1079
- declare type RouterResolve<TRoutes extends Routes> = {
1080
- <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterResolveArgs<TRoutes, TSource>): Url;
1081
- (url: Url, options?: RouterResolveOptions): Url;
1082
- };
1064
+ declare type RouterResolve<TRoutes extends Routes> = <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterResolveArgs<TRoutes, TSource>) => ResolvedRoute;
1083
1065
 
1084
- 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];
1066
+ declare type RouterResolveArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>> = AllPropertiesAreOptional<RouteParamsByKey<TRoutes, TSource>> extends true ? [params?: RouteParamsByKey<TRoutes, TSource>, options?: RouterResolveOptions<RouteStateByName<TRoutes, TSource>>] : [params: RouteParamsByKey<TRoutes, TSource>, options?: RouterResolveOptions<RouteStateByName<TRoutes, TSource>>];
1085
1067
 
1086
- declare type RouterResolveOptions = {
1068
+ declare type RouterResolveOptions<TState = unknown> = {
1087
1069
  query?: QuerySource;
1088
1070
  hash?: string;
1071
+ state?: Partial<TState>;
1089
1072
  };
1090
1073
 
1091
1074
  declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = {
@@ -1095,9 +1078,10 @@ declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = {
1095
1078
  readonly matches: TRoute['matches'];
1096
1079
  readonly hash: TRoute['hash'];
1097
1080
  readonly update: RouteUpdate<TRoute>;
1081
+ readonly href: TRoute['href'];
1098
1082
  params: TRoute['params'];
1099
1083
  state: TRoute['state'];
1100
- get query(): ResolvedRouteQuery;
1084
+ get query(): URLSearchParams;
1101
1085
  set query(value: QuerySource);
1102
1086
  };
1103
1087
 
@@ -1115,7 +1099,7 @@ export declare const RouterView: __VLS_WithTemplateSlots<DefineComponent< {
1115
1099
  name?: string;
1116
1100
  }, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{
1117
1101
  name?: string;
1118
- } & {}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}>, Readonly<{
1102
+ }> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>, Readonly<{
1119
1103
  default?: (props: {
1120
1104
  route: RouterRoute;
1121
1105
  component: Component;
@@ -1154,6 +1138,8 @@ declare type RouteWithMatch<TRoute extends RouterRoute, TRouteName extends TRout
1154
1138
 
1155
1139
  declare type StringHasValue<T> = string extends T ? true : '' extends T ? false : T extends string ? true : false;
1156
1140
 
1141
+ declare type ToCallback = (resolve: RegisteredRouter['resolve']) => ResolvedRoute | Url | undefined;
1142
+
1157
1143
  declare type ToHash<T extends string | Hash | undefined> = T extends string ? Hash<T> : T extends undefined ? Hash<''> : unknown extends T ? Hash<''> : T;
1158
1144
 
1159
1145
  declare type ToHost<T extends string | Host | undefined> = T extends string ? Host<T, {}> : T extends undefined ? Host<'', {}> : unknown extends T ? Host<'', {}> : T;
@@ -1170,7 +1156,7 @@ export declare type UrlParts = {
1170
1156
  protocol?: string;
1171
1157
  host?: string;
1172
1158
  pathname: string;
1173
- searchParams: URLSearchParams;
1159
+ searchParams: QuerySource;
1174
1160
  search: string;
1175
1161
  hash: string;
1176
1162
  };
@@ -1187,7 +1173,7 @@ export declare type UseLink = {
1187
1173
  /**
1188
1174
  * Resolved URL with params interpolated and query applied. Same value as `router.resolve`.
1189
1175
  */
1190
- href: ComputedRef<string>;
1176
+ href: ComputedRef<Url | undefined>;
1191
1177
  /**
1192
1178
  * True if route matches current URL or is ancestor of route that matches current URL
1193
1179
  */
@@ -1225,9 +1211,13 @@ export declare function useLink<TRouteKey extends RegisteredRoutesName>(name: Ma
1225
1211
 
1226
1212
  export declare function useLink(url: MaybeRefOrGetter<Url>, options?: MaybeRefOrGetter<UseLinkOptions>): UseLink;
1227
1213
 
1214
+ export declare function useLink(resolvedRoute: MaybeRefOrGetter<ResolvedRoute | undefined>, options?: MaybeRefOrGetter<UseLinkOptions>): UseLink;
1215
+
1216
+ export declare function useLink(source: MaybeRefOrGetter<string | ResolvedRoute | undefined>, paramsOrOptions?: MaybeRefOrGetter<Record<PropertyKey, unknown> | UseLinkOptions>, maybeOptions?: MaybeRefOrGetter<UseLinkOptions>): UseLink;
1217
+
1228
1218
  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>];
1229
1219
 
1230
- export declare type UseLinkOptions = RouterResolveOptions & {
1220
+ export declare type UseLinkOptions = RouterPushOptions & {
1231
1221
  prefetch?: PrefetchConfig;
1232
1222
  };
1233
1223