@kitbag/router 0.7.0 → 0.7.2

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
@@ -11,7 +11,7 @@ Type safe router for Vue.js
11
11
 
12
12
  ## Getting Started
13
13
 
14
- Get Started with our [documentation](https://kitbag-router.netlify.app/)
14
+ Get Started with our [documentation](https://kitbag-router.netlify.app/) or our [intro video](https://kitbag-router.netlify.app/)
15
15
 
16
16
  ## Installation
17
17
 
@@ -75,31 +75,32 @@ declare module '@kitbag/router' {
75
75
  To navigate to another route, you can use `router.push`. This method will update the URL for the browser and also add the URL into the history so when a user uses the back button on their browser it will behave as expected.
76
76
 
77
77
  ```ts
78
+ import { defineAsyncComponent } from 'vue'
78
79
  import { createRoute, useRouter } from '@kitbag/router'
79
80
 
80
81
  const user = createRoute({
81
82
  name: 'user',
82
83
  path: '/user',
83
- component: ...,
84
+ component: defineAsyncComponent(() => import('./UserPage.vue')),
84
85
  })
85
86
 
86
87
  const profile = createRoute({
87
88
  parent: user,
88
89
  name: 'profile',
89
90
  path: '/profile',
90
- component: ...,
91
+ component: defineAsyncComponent(() => import('./ProfilePage.vue')),
91
92
  })
92
93
 
93
94
  const settings = createRoute({
94
95
  parent: user,
95
96
  name: 'settings',
96
97
  path: '/settings',
97
- component: ...,
98
+ component: defineAsyncComponent(() => import('./SettingsPage.vue')),
98
99
  })
99
100
 
100
101
  const router = useRouter([user, profile, settings])
101
102
 
102
- router.push('user.settings')
103
+ router.push('settings')
103
104
  ```
104
105
 
105
106
  The push method also accepts a plain string if you know the URL you want to go to.
@@ -109,14 +110,14 @@ router.push('/user/settings')
109
110
  router.push('https://github.com/kitbagjs/router')
110
111
  ```
111
112
 
112
- 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.
113
114
 
114
115
  ## Update
115
116
 
116
117
  If you only wish to change the params on the current route you can use `router.route.update`.
117
118
 
118
119
  ```ts
119
- router.route.update('myParam': 123)
120
+ router.route.update('myParam', 123)
120
121
  ```
121
122
 
122
123
  or for setting multiple params at once
@@ -162,6 +163,6 @@ This component gives the router the power to change the URL without reloading th
162
163
  [netlify-badge]: https://api.netlify.com/api/v1/badges/c12f79b8-49f9-4529-bc23-f8ffca8919a3/deploy-status
163
164
  [netlify-url]: https://app.netlify.com/sites/kitbag-router/deploys
164
165
  [discord-badge]: https://img.shields.io/discord/1079625926024900739?logo=discord&label=Discord
165
- [discord-url]: https://discord.gg/UT7JrAxU
166
+ [discord-url]: https://discord.gg/zw7dpcc5HV
166
167
  [stackblitz-badge]: https://developer.stackblitz.com/img/open_in_stackblitz_small.svg
167
168
  [stackblitz-url]: https://stackblitz.com/~/github.com/kitbagjs/router-preview
@@ -121,7 +121,7 @@ declare const builtInRejections: ['NotFound'];
121
121
 
122
122
  declare type BuiltInRejectionType = typeof builtInRejections[number];
123
123
 
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 : '';
124
+ declare type CombineMeta<TParent extends Record<string, unknown>, TChild extends Record<string, unknown>> = TParent & TChild;
125
125
 
126
126
  declare type CombinePath<TParent extends Path, TChild extends Path> = ToPath<TParent> extends {
127
127
  path: infer TParentPath extends string;
@@ -141,6 +141,8 @@ declare type CombineQuery<TParent extends Query, TChild extends Query> = ToQuery
141
141
 
142
142
  declare type CombineQueryString<TParent extends string | undefined, TChild extends string | undefined> = StringHasValue<TParent> extends true ? StringHasValue<TChild> extends true ? `${TParent}&${TChild}` : TParent : TChild;
143
143
 
144
+ declare type CombineState<TParent extends Record<string, Param>, TChild extends Record<string, Param>> = TParent & TChild;
145
+
144
146
  /**
145
147
  * Creates a component wrapper which has no props itself but mounts another component within while binding its props
146
148
  *
@@ -167,9 +169,9 @@ declare type ComponentPropsGetter<TComponent extends Component> = () => MaybePro
167
169
 
168
170
  declare type Constructor = new (...args: any) => any;
169
171
 
170
- 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>>;
172
+ 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>>;
171
173
 
172
- 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>>>;
174
+ 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>>>;
173
175
 
174
176
  export declare function createParam<TParam extends ParamWithDefault>(param: TParam): TParam;
175
177
 
@@ -177,17 +179,17 @@ export declare function createParam<TParam extends Param>(param: TParam): ParamG
177
179
 
178
180
  export declare function createParam<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
179
181
 
180
- 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>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithoutParent): Route<ToKey<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>>;
182
+ 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>;
181
183
 
182
- 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>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithParent<TParent>): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>>;
184
+ 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']>>;
183
185
 
184
- 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>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery>> & WithoutParent): Route<ToKey<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>>;
186
+ 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>;
185
187
 
186
- 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>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent>): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>>;
188
+ 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']>>;
187
189
 
188
- 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>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery>> & WithoutParent): Route<ToKey<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>>;
190
+ 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>;
189
191
 
190
- 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>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent>): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>>;
192
+ 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']>>;
191
193
 
192
194
  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> = {
193
195
  /**
@@ -211,7 +213,7 @@ export declare type CreateRouteOptions<TName extends string | undefined = string
211
213
  /**
212
214
  * The Route properties originally provided to `createRoute`. The only change is normalizing meta to always default to an empty object.
213
215
  */
214
- export declare type CreateRouteOptionsMatched = CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithComponent | WithComponents | WithoutComponents) & (WithParent | WithoutParent) & {
216
+ declare type CreateRouteOptionsMatched = CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithComponent | WithComponents | WithoutComponents) & (WithParent | WithoutParent) & (WithState | WithoutState) & {
215
217
  meta: RouteMeta;
216
218
  };
217
219
 
@@ -243,8 +245,8 @@ export declare function createRouter<const T extends Routes>(routes: T, options?
243
245
  export declare function createRouter<const T extends Routes>(arrayOfRoutes: T[], options?: RouterOptions): Router<T>;
244
246
 
245
247
  /**
246
- * An error thrown when duplicate parameters are detected in a route when creating a router.
247
- * When defining routes, param names must be unique. This includes params defined in a path
248
+ * An error thrown when duplicate parameters are detected in a route.
249
+ * Param names must be unique. This includes params defined in a path
248
250
  * parent and params defined in the query.
249
251
  */
250
252
  export declare class DuplicateParamsError extends Error {
@@ -335,6 +337,14 @@ declare type ExtractRouteParamTypesWithoutLosingOptional<TRoute> = TRoute extend
335
337
  };
336
338
  } ? ExtractParamTypesWithoutLosingOptional<HostParams & PathParams & QueryParams> : Record<string, unknown>;
337
339
 
340
+ declare type ExtractRouteStateParamsAsOptional<T extends Record<string, Param>> = ExtractParamTypes<{
341
+ [K in keyof T as K extends string ? `?${K}` : never]: T[K];
342
+ }>;
343
+
344
+ declare type ExtractStateParams<TRoute> = TRoute extends {
345
+ state: infer TState extends Record<string, Param>;
346
+ } ? ExtractParamTypes<TState> : Record<string, unknown>;
347
+
338
348
  declare type Host<THost extends string = string, TParams extends HostParamsWithParamNameExtracted<THost> = Record<string, Param | undefined>> = {
339
349
  host: THost;
340
350
  params: string extends THost ? Record<string, Param> : Identity<ExtractParamsFromHostString<THost, TParams>>;
@@ -355,33 +365,33 @@ export declare function isParamWithDefault(param: Param): param is ParamWithDefa
355
365
 
356
366
  export declare function isRoute(route: unknown): route is RouterRoute;
357
367
 
358
- export declare function isRoute<TRoute extends RouterRoute, TRouteKey extends TRoute['key']>(route: TRoute, routeKey: TRouteKey, options: IsRouteOptions & {
368
+ export declare function isRoute<TRoute extends RouterRoute, TRouteName extends TRoute['name']>(route: TRoute, routeName: TRouteName, options: IsRouteOptions & {
359
369
  exact: true;
360
370
  }): route is TRoute & {
361
- key: TRouteKey;
371
+ name: TRouteName;
362
372
  };
363
373
 
364
- export declare function isRoute<TRoute extends RouterRoute, TRouteKey extends TRoute['key']>(route: TRoute, routeKey: TRouteKey, options?: IsRouteOptions): route is TRoute & {
365
- key: `${TRouteKey}${string}`;
374
+ export declare function isRoute<TRoute extends RouterRoute, TRouteName extends TRoute['name']>(route: TRoute, routeName: TRouteName, options?: IsRouteOptions): route is TRoute & {
375
+ name: `${TRouteName}${string}`;
366
376
  };
367
377
 
368
- export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options: IsRouteOptions & {
378
+ export declare function isRoute<TRouteName extends RegisteredRoutesName>(route: unknown, routeName: TRouteName, options: IsRouteOptions & {
369
379
  exact: true;
370
380
  }): route is RegisteredRouterRoute & {
371
- key: TRouteKey;
381
+ name: TRouteName;
372
382
  };
373
383
 
374
- export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options?: IsRouteOptions): route is RegisteredRouterRoute & {
375
- key: `${TRouteKey}${string}`;
384
+ export declare function isRoute<TRouteName extends RegisteredRoutesName>(route: unknown, routeName: TRouteName, options?: IsRouteOptions): route is RegisteredRouterRoute & {
385
+ name: `${TRouteName}${string}`;
376
386
  };
377
387
 
378
- export declare function isRoute(route: unknown, routeKey?: string, options?: IsRouteOptions): boolean;
388
+ export declare function isRoute(route: unknown, routeName?: string, options?: IsRouteOptions): boolean;
379
389
 
380
390
  declare type IsRouteOptions = {
381
391
  exact?: boolean;
382
392
  };
383
393
 
384
- declare type IsRouteUnnamed<T extends Route> = StringHasValue<T['key']> extends true ? false : true;
394
+ declare type IsRouteUnnamed<T extends Route> = StringHasValue<T['name']> extends true ? false : true;
385
395
 
386
396
  declare type MakeOptional<T> = {
387
397
  [P in WithOptionalProperties<T>]?: T[P];
@@ -564,7 +574,7 @@ export declare type RegisteredRejectionType = Register extends {
564
574
  } ? TRejections[number] : never;
565
575
 
566
576
  /**
567
- * Represents the a map of all possible RouteKeys with corresponding Route registered within {@link Register}
577
+ * Represents the a map of all possible route names with corresponding Route registered within {@link Register}
568
578
  */
569
579
  export declare type RegisteredRouteMap = RoutesMap<RegisteredRoutes>;
570
580
 
@@ -598,9 +608,9 @@ export declare type RegisteredRoutes = Register extends {
598
608
  } ? TRoutes : Route[];
599
609
 
600
610
  /**
601
- * Represents the union of all possible RouteKeys registered within {@link Register}
611
+ * Represents the union of all possible route names registered within {@link Register}
602
612
  */
603
- export declare type RegisteredRoutesKey = RoutesKey<RegisteredRoutes>;
613
+ export declare type RegisteredRoutesName = RoutesName<RegisteredRoutes>;
604
614
 
605
615
  declare type RemoveLeadingQuestionMark<T extends PropertyKey> = T extends `?${infer TRest extends string}` ? TRest : T;
606
616
 
@@ -623,9 +633,9 @@ declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
623
633
  */
624
634
  matches: TRoute['matches'];
625
635
  /**
626
- * Unique identifier for the route, generated by joining route `name` by period. Key is used for routing and for matching.
636
+ * Unique identifier for the route. Name is used for routing and for matching.
627
637
  */
628
- key: TRoute['key'];
638
+ name: TRoute['name'];
629
639
  /**
630
640
  * Accessor for query string values from user in the current browser location.
631
641
  */
@@ -634,6 +644,10 @@ declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
634
644
  * Key value pair for route params, values will be the user provided value from current browser location.
635
645
  */
636
646
  params: ExtractRouteParamTypes<TRoute>;
647
+ /**
648
+ * Type for additional data intended to be stored in history state.
649
+ */
650
+ state: ExtractRouteStateParamsAsOptional<TRoute['state']>;
637
651
  }>;
638
652
 
639
653
  declare type ResolvedRouteQuery = {
@@ -643,26 +657,24 @@ declare type ResolvedRouteQuery = {
643
657
 
644
658
  /**
645
659
  * Represents the structure of a route within the application. Return value of `createRoute`
646
- * @template TKey - Represents the unique key identifying the route, typically a string.
660
+ * @template TName - Represents the unique name identifying the route, typically a string.
647
661
  * @template TPath - The type or structure of the route's path.
648
662
  * @template TQuery - The type or structure of the query parameters associated with the route.
649
663
  */
650
- export declare type Route<TKey extends string = string, THost extends Host = Host, TPath extends Path = Path, TQuery extends Query = Query, TMeta extends RouteMeta = RouteMeta> = {
664
+ 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>> = {
651
665
  /**
652
666
  * The specific route properties that were matched in the current route.
653
667
  */
654
- matched: CreateRouteOptionsMatched & {
655
- meta: TMeta;
656
- };
668
+ matched: CreateRouteOptionsMatched;
657
669
  /**
658
670
  * The specific route properties that were matched in the current route, including any ancestors.
659
671
  * Order of routes will be from greatest ancestor to narrowest matched.
660
672
  */
661
673
  matches: CreateRouteOptionsMatched[];
662
674
  /**
663
- * Unique identifier for the route, generated by joining route `name` by period. Key is used for routing and for matching.
675
+ * Unique identifier for the route. Name is used for routing and for matching.
664
676
  */
665
- key: TKey;
677
+ name: TName;
666
678
  /**
667
679
  * Represents the host for this route. Used for external routes.
668
680
  */
@@ -675,10 +687,18 @@ export declare type Route<TKey extends string = string, THost extends Host = Hos
675
687
  * Represents the structured query of the route, including query params.
676
688
  */
677
689
  query: TQuery;
690
+ /**
691
+ * Represents additional metadata associated with a route, combined with any parents.
692
+ */
693
+ meta: TMeta;
694
+ /**
695
+ * Represents the schema of the route state, combined with any parents.
696
+ */
697
+ state: TState;
678
698
  depth: number;
679
699
  };
680
700
 
681
- declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesKey<TRoutes>> = RoutesMap<TRoutes>[TKey];
701
+ declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesName<TRoutes>> = RoutesMap<TRoutes>[TKey];
682
702
 
683
703
  /**
684
704
  * Generic type representing a route hook, which can be either before or after a route change.
@@ -834,11 +854,11 @@ export declare type Router<TRoutes extends Routes = any> = Plugin_2 & {
834
854
  };
835
855
 
836
856
  declare type RouterFind<TRoutes extends Routes> = {
837
- <TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterFindArgs<TRoutes, TSource>): ResolvedRoute | undefined;
838
- (source: Url): ResolvedRoute | undefined;
857
+ <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterFindArgs<TRoutes, TSource>): ResolvedRoute | undefined;
858
+ (url: Url): ResolvedRoute | undefined;
839
859
  };
840
860
 
841
- declare type RouterFindArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams] : [params: TParams];
861
+ declare type RouterFindArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams] : [params: TParams];
842
862
 
843
863
  declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
844
864
 
@@ -882,21 +902,29 @@ export declare type RouterOptions = {
882
902
  */
883
903
  initialUrl?: string;
884
904
  /**
885
- * Specifies the history mode for the router, such as 'hash', 'history', or 'abstract'.
905
+ * Specifies the history mode for the router, such as "browser", "memory", or "hash".
906
+ *
907
+ * @default "auto"
886
908
  */
887
909
  historyMode?: RouterHistoryMode;
910
+ /**
911
+ * Base path to be prepended to any URL. Can be used for Vue applications that run in nested folder for domain.
912
+ * For example having `base` of `/foo` would assume all routes should start with `your.domain.com/foo`.
913
+ */
914
+ base?: string;
888
915
  } & RouterRejectionComponents;
889
916
 
890
917
  declare type RouterPush<TRoutes extends Routes = any> = {
891
- <TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterPushArgs<TRoutes, TSource>): Promise<void>;
892
- (source: Url, options?: RouterPushOptions): Promise<void>;
918
+ <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterPushArgs<TRoutes, TSource>): Promise<void>;
919
+ (url: Url, options?: RouterPushOptions): Promise<void>;
893
920
  };
894
921
 
895
- declare type RouterPushArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterPushOptions] : [params: TParams, options?: RouterPushOptions];
922
+ 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>>];
896
923
 
897
- declare type RouterPushOptions = {
924
+ declare type RouterPushOptions<TState = unknown> = {
898
925
  query?: Record<string, string>;
899
926
  replace?: boolean;
927
+ state?: Partial<TState>;
900
928
  };
901
929
 
902
930
  export declare type RouterReject = (type: RouterRejectionType) => void;
@@ -915,29 +943,33 @@ export declare const routerRejectionKey: InjectionKey<RouterRejection>;
915
943
  declare type RouterRejectionType = BuiltInRejectionType | RegisteredRejectionType;
916
944
 
917
945
  declare type RouterReplace<TRoutes extends Routes> = {
918
- <TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
919
- (source: Url, options?: RouterReplaceOptions): Promise<void>;
946
+ <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
947
+ (url: Url, options?: RouterReplaceOptions): Promise<void>;
920
948
  };
921
949
 
922
- declare type RouterReplaceArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterReplaceOptions] : [params: TParams, options?: RouterReplaceOptions];
950
+ 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>>];
923
951
 
924
- declare type RouterReplaceOptions = Omit<RouterPushOptions, 'replace'>;
952
+ declare type RouterReplaceOptions<TState = unknown> = {
953
+ query?: Record<string, string>;
954
+ state?: Partial<TState>;
955
+ };
925
956
 
926
957
  declare type RouterResolve<TRoutes extends Routes> = {
927
- <TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterResolveArgs<TRoutes, TSource>): string;
928
- (source: Url, options?: RouterResolveOptions): string;
958
+ <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterResolveArgs<TRoutes, TSource>): string;
959
+ (url: Url, options?: RouterResolveOptions): string;
929
960
  };
930
961
 
931
- 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];
962
+ 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];
932
963
 
933
964
  declare type RouterResolveOptions = {
934
965
  query?: Record<string, string>;
935
966
  };
936
967
 
937
968
  declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = Readonly<{
938
- key: TRoute['key'];
969
+ name: TRoute['name'];
939
970
  matched: TRoute['matched'];
940
971
  matches: TRoute['matches'];
972
+ state: TRoute['state'];
941
973
  query: ResolvedRouteQuery;
942
974
  params: Writable<TRoute['params']>;
943
975
  update: RouteUpdate<TRoute>;
@@ -957,18 +989,24 @@ name?: string | undefined;
957
989
  }>>>, {}, {}>, Readonly<{
958
990
  default?: ((props: {
959
991
  route: Readonly<{
960
- key: string;
961
- matched: CreateRouteOptionsMatched & {
992
+ name: string;
993
+ matched: CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
994
+ meta: Record<string, unknown>;
995
+ };
996
+ matches: (CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
962
997
  meta: Record<string, unknown>;
998
+ })[];
999
+ state: {
1000
+ [x: string]: any;
1001
+ [x: number]: any;
963
1002
  };
964
- matches: CreateRouteOptionsMatched[];
965
1003
  query: ResolvedRouteQuery;
966
1004
  params: Writable< {
967
1005
  [x: string]: any;
968
1006
  [x: number]: any;
969
1007
  }>;
970
1008
  update: {
971
- (key: string, value: unknown, options?: RouterPushOptions | undefined): Promise<void>;
1009
+ (paramName: string, paramValue: unknown, options?: RouterPushOptions | undefined): Promise<void>;
972
1010
  (params: Partial<{
973
1011
  [x: string]: any;
974
1012
  [x: number]: any;
@@ -986,18 +1024,24 @@ name?: string | undefined;
986
1024
  }> & {
987
1025
  default?: ((props: {
988
1026
  route: Readonly<{
989
- key: string;
990
- matched: CreateRouteOptionsMatched & {
1027
+ name: string;
1028
+ matched: CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
991
1029
  meta: Record<string, unknown>;
992
1030
  };
993
- matches: CreateRouteOptionsMatched[];
1031
+ matches: (CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
1032
+ meta: Record<string, unknown>;
1033
+ })[];
1034
+ state: {
1035
+ [x: string]: any;
1036
+ [x: number]: any;
1037
+ };
994
1038
  query: ResolvedRouteQuery;
995
1039
  params: Writable< {
996
1040
  [x: string]: any;
997
1041
  [x: number]: any;
998
1042
  }>;
999
1043
  update: {
1000
- (key: string, value: unknown, options?: RouterPushOptions | undefined): Promise<void>;
1044
+ (paramName: string, paramValue: unknown, options?: RouterPushOptions | undefined): Promise<void>;
1001
1045
  (params: Partial<{
1002
1046
  [x: string]: any;
1003
1047
  [x: number]: any;
@@ -1019,17 +1063,19 @@ name?: string | undefined;
1019
1063
  */
1020
1064
  export declare type Routes = Readonly<Route[]>;
1021
1065
 
1022
- declare type RoutesKey<TRoutes extends Routes> = string & keyof RoutesMap<TRoutes>;
1023
-
1024
1066
  declare type RoutesMap<TRoutes extends Routes = []> = {
1025
- [K in TRoutes[number] as AsNamedRoute<K>['key']]: AsNamedRoute<K>;
1067
+ [K in TRoutes[number] as AsNamedRoute<K>['name']]: AsNamedRoute<K>;
1026
1068
  };
1027
1069
 
1070
+ declare type RoutesName<TRoutes extends Routes> = string & keyof RoutesMap<TRoutes>;
1071
+
1072
+ declare type RouteStateByName<TRoutes extends Routes, TName extends string> = ExtractStateParams<RouteGetByKey<TRoutes, TName>>;
1073
+
1028
1074
  declare type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = ResolvedRoute extends TRoute ? {
1029
- (key: string, value: unknown, options?: RouterPushOptions): Promise<void>;
1075
+ (paramName: string, paramValue: unknown, options?: RouterPushOptions): Promise<void>;
1030
1076
  (params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
1031
1077
  } : {
1032
- <TKey extends keyof TRoute['params']>(key: TKey, value: TRoute['params'][TKey], options?: RouterPushOptions): Promise<void>;
1078
+ <TParamName extends keyof TRoute['params']>(paramName: TParamName, paramValue: TRoute['params'][TParamName], options?: RouterPushOptions): Promise<void>;
1033
1079
  (params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
1034
1080
  };
1035
1081
 
@@ -1039,7 +1085,7 @@ declare type ToCallback = (resolve: RegisteredRouter['resolve']) => string;
1039
1085
 
1040
1086
  declare type ToHost<T extends string | Host | undefined> = T extends string ? Host<T, {}> : T extends undefined ? Host<'', {}> : unknown extends T ? Host<'', {}> : T;
1041
1087
 
1042
- declare type ToKey<T extends string | undefined> = T extends string ? T : '';
1088
+ declare type ToName<T extends string | undefined> = T extends string ? T : '';
1043
1089
 
1044
1090
  declare type ToPath<T extends string | Path | undefined> = T extends string ? Path<T, {}> : T extends undefined ? Path<'', {}> : unknown extends T ? Path<'', {}> : T;
1045
1091
 
@@ -1079,17 +1125,17 @@ export declare type UseLink = {
1079
1125
  * or resolved URL to discover route details. Also exports some useful context about routes relationship to current URL and convenience methods
1080
1126
  * for navigating.
1081
1127
  *
1082
- * @param source - The key of the route or the URL value.
1083
- * @param params - If providing route key, this argument will expect corresponding params.
1128
+ * @param source - The name of the route or the URL value.
1129
+ * @param params - If providing route name, this argument will expect corresponding params.
1084
1130
  * @param options - {@link RouterResolveOptions}Same options as router resolve.
1085
1131
  * @returns {UseLink} Reactive context values for as well as navigation methods.
1086
1132
  *
1087
1133
  */
1088
- export declare function useLink<TRouteKey extends RegisteredRoutesKey>(routeKey: MaybeRefOrGetter<TRouteKey>, ...args: UseLinkArgs<TRouteKey>): UseLink;
1134
+ export declare function useLink<TRouteKey extends RegisteredRoutesName>(name: MaybeRefOrGetter<TRouteKey>, ...args: UseLinkArgs<TRouteKey>): UseLink;
1089
1135
 
1090
1136
  export declare function useLink(url: MaybeRefOrGetter<Url>): UseLink;
1091
1137
 
1092
- 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>];
1138
+ declare type UseLinkArgs<TSource extends RegisteredRoutesName, TParams = RouteParamsByKey<RegisteredRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<RouterResolveOptions>] : [params: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<RouterResolveOptions>];
1093
1139
 
1094
1140
  /**
1095
1141
  * A composition to access the router's rejection state.
@@ -1102,29 +1148,29 @@ declare type UseLinkArgs<TSource extends RegisteredRoutesKey, TParams = RoutePar
1102
1148
  export declare function useRejection(): RouterRejection;
1103
1149
 
1104
1150
  /**
1105
- * A composition to access the current route or verify a specific route key within a Vue component.
1151
+ * A composition to access the current route or verify a specific route name within a Vue component.
1106
1152
  * This function provides two overloads:
1107
1153
  * 1. When called without arguments, it returns the current route from the router without types.
1108
- * 2. When called with a route key, it checks if the current active route includes the specified route key.
1154
+ * 2. When called with a route name, it checks if the current active route includes the specified route name.
1109
1155
  *
1110
- * @template TRouteKey - A string type that should match route key of RegisteredRouteMap, ensuring the route key exists.
1111
- * @param routeKey - Optional. The key of the route to validate against the current active routes.
1112
- * @returns The current router route. If a route key is provided, it validates the route key first.
1113
- * @throws {UseRouteInvalidError} Throws an error if the provided route key is not valid or does not match the current route.
1156
+ * @template TRouteName - A string type that should match route name of RegisteredRouteMap, ensuring the route name exists.
1157
+ * @param routeName - Optional. The name of the route to validate against the current active routes.
1158
+ * @returns The current router route. If a route name is provided, it validates the route name first.
1159
+ * @throws {UseRouteInvalidError} Throws an error if the provided route name is not valid or does not match the current route.
1114
1160
  *
1115
- * The function also sets up a reactive watcher on the route object from the router to continually check the validity of the route key
1161
+ * The function also sets up a reactive watcher on the route object from the router to continually check the validity of the route name
1116
1162
  * if provided, throwing an error if the validation fails at any point during the component's lifecycle.
1117
1163
  */
1118
1164
  export declare function useRoute(): RegisteredRouterRoute;
1119
1165
 
1120
- export declare function useRoute<TRouteKey extends RegisteredRoutesKey>(routeKey: TRouteKey, options: IsRouteOptions & {
1166
+ export declare function useRoute<TRouteName extends RegisteredRoutesName>(routeName: TRouteName, options: IsRouteOptions & {
1121
1167
  exact: true;
1122
1168
  }): RegisteredRouterRoute & {
1123
- key: TRouteKey;
1169
+ name: TRouteName;
1124
1170
  };
1125
1171
 
1126
- export declare function useRoute<TRouteKey extends RegisteredRoutesKey>(routeKey: TRouteKey, options?: IsRouteOptions): RegisteredRouterRoute & {
1127
- key: `${TRouteKey}${string}`;
1172
+ export declare function useRoute<TRouteName extends RegisteredRoutesName>(routeName: TRouteName, options?: IsRouteOptions): RegisteredRouterRoute & {
1173
+ name: `${TRouteName}${string}`;
1128
1174
  };
1129
1175
 
1130
1176
  /**
@@ -1206,10 +1252,21 @@ declare type WithoutParent = {
1206
1252
  parent?: never;
1207
1253
  };
1208
1254
 
1255
+ declare type WithoutState = {
1256
+ state?: never;
1257
+ };
1258
+
1209
1259
  declare type WithParent<TParent extends Route = Route> = {
1210
1260
  parent: TParent;
1211
1261
  };
1212
1262
 
1263
+ declare type WithState<TState extends Record<string, Param> = Record<string, Param>> = {
1264
+ /**
1265
+ * Type params for additional data intended to be stored in history state, all keys will be optional unless a default is provided.
1266
+ */
1267
+ state: TState;
1268
+ };
1269
+
1213
1270
  declare type Writable<T> = {
1214
1271
  -readonly [P in keyof T]: T[P];
1215
1272
  };
@@ -1217,7 +1274,7 @@ declare type Writable<T> = {
1217
1274
  export { }
1218
1275
 
1219
1276
 
1220
- declare module '@vue/runtime-core' {
1277
+ declare module 'vue' {
1221
1278
  interface GlobalComponents {
1222
1279
  RouterView: typeof RouterView;
1223
1280
  RouterLink: typeof RouterLink;