@kitbag/router 0.1.1 → 0.3.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 +16 -5
- package/dist/kitbag-router.d.ts +182 -46
- package/dist/kitbag-router.js +956 -835
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Type safe router for Vue.js
|
|
4
4
|
|
|
5
|
-
[![
|
|
6
|
-
[![Netlify Status]
|
|
5
|
+
[![NPM Version][npm-badge]][npm-url]
|
|
6
|
+
[![Netlify Status][netlify-badge]][netlify-url]
|
|
7
|
+
[![Discord chat][discord-badge]][discord-url]
|
|
8
|
+
[![Open in StackBlitz][stackblitz-badge]][stackblitz-url]
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
## Getting Started
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
Get Started with our [documentation](https://kitbag-router.netlify.app/)
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
## Installation
|
|
13
15
|
|
|
14
16
|
```bash
|
|
15
17
|
# bun
|
|
@@ -152,3 +154,12 @@ Use RouterLink for navigating between routes.
|
|
|
152
154
|
```
|
|
153
155
|
|
|
154
156
|
This component gives the router the power to change the URL without reloading the page.
|
|
157
|
+
|
|
158
|
+
[npm-badge]: https://img.shields.io/npm/v/@kitbag/router.svg
|
|
159
|
+
[npm-url]: https://www.npmjs.org/package/@kitbag/router
|
|
160
|
+
[netlify-badge]: https://api.netlify.com/api/v1/badges/c12f79b8-49f9-4529-bc23-f8ffca8919a3/deploy-status
|
|
161
|
+
[netlify-url]: https://app.netlify.com/sites/kitbag-router/deploys
|
|
162
|
+
[discord-badge]: https://img.shields.io/discord/1079625926024900739?logo=discord&label=Discord
|
|
163
|
+
[discord-url]: https://discord.gg/UT7JrAxU
|
|
164
|
+
[stackblitz-badge]: https://developer.stackblitz.com/img/open_in_stackblitz_small.svg
|
|
165
|
+
[stackblitz-url]: https://stackblitz.com/~/github.com/kitbagjs/router-preview
|
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -4,14 +4,21 @@ import { ComponentOptionsMixin } from 'vue';
|
|
|
4
4
|
import { DeepReadonly } from 'vue';
|
|
5
5
|
import { DefineComponent } from 'vue';
|
|
6
6
|
import { ExtractPropTypes } from 'vue';
|
|
7
|
+
import { FunctionalComponent } from 'vue';
|
|
7
8
|
import { InjectionKey } from 'vue';
|
|
9
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
8
10
|
import { Plugin as Plugin_2 } from 'vue';
|
|
9
11
|
import { PropType } from 'vue';
|
|
10
12
|
import { PublicProps } from 'vue';
|
|
11
13
|
import { Ref } from 'vue';
|
|
14
|
+
import { RendererElement } from 'vue';
|
|
15
|
+
import { RendererNode } from 'vue';
|
|
16
|
+
import { VNode } from 'vue';
|
|
12
17
|
|
|
13
18
|
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
14
19
|
|
|
20
|
+
declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T;
|
|
21
|
+
|
|
15
22
|
declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
16
23
|
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
17
24
|
type: PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
@@ -21,6 +28,15 @@ declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
|
21
28
|
};
|
|
22
29
|
};
|
|
23
30
|
|
|
31
|
+
declare type __VLS_TypePropsToRuntimeProps_2<T> = {
|
|
32
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
33
|
+
type: PropType<__VLS_NonUndefinedable_2<T[K]>>;
|
|
34
|
+
} : {
|
|
35
|
+
type: PropType<T[K]>;
|
|
36
|
+
required: true;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
24
40
|
declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
25
41
|
new (): {
|
|
26
42
|
$slots: S;
|
|
@@ -127,7 +143,7 @@ declare type BuiltInRejectionType = typeof builtInRejections[number];
|
|
|
127
143
|
/**
|
|
128
144
|
* Represents properties for child routes, including required component, name, and path.
|
|
129
145
|
*/
|
|
130
|
-
export declare type ChildRouteProps = WithHooks & {
|
|
146
|
+
export declare type ChildRouteProps = (WithComponent | WithComponents) & WithHooks & {
|
|
131
147
|
/**
|
|
132
148
|
* Name for route, used to create route keys and in navigation.
|
|
133
149
|
*/
|
|
@@ -144,10 +160,6 @@ export declare type ChildRouteProps = WithHooks & {
|
|
|
144
160
|
* Query (aka search) part of URL.
|
|
145
161
|
*/
|
|
146
162
|
query?: string | Query;
|
|
147
|
-
/**
|
|
148
|
-
* Type alias for Vue components, which can be either synchronous or asynchronous components.
|
|
149
|
-
*/
|
|
150
|
-
component: RouteComponent;
|
|
151
163
|
/**
|
|
152
164
|
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
153
165
|
*/
|
|
@@ -174,6 +186,30 @@ declare type CombineQuery<TParent extends Query | undefined, TChild extends Quer
|
|
|
174
186
|
|
|
175
187
|
declare type CombineQueryString<TParent extends string | undefined, TChild extends string | undefined> = StringHasValue<TParent> extends true ? StringHasValue<TChild> extends true ? `${TParent}&${TChild}` : TParent : TChild;
|
|
176
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Creates a component wrapper which has no props itself but mounts another component within while binding its props
|
|
191
|
+
*
|
|
192
|
+
* @param component The component to mount
|
|
193
|
+
* @param props A callback that returns the props or attributes to bind to the component
|
|
194
|
+
* @returns A component
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { createRoutes, component } from '@kitbag/router'
|
|
199
|
+
*
|
|
200
|
+
* export const routes = createRoutes([
|
|
201
|
+
* {
|
|
202
|
+
* name: 'User',
|
|
203
|
+
* path: '/',
|
|
204
|
+
* component: component(User, () => ({ userId: 1 }))
|
|
205
|
+
* },
|
|
206
|
+
* ])
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export declare function component<TComponent extends Component>(component: TComponent, props: PropsGetter<TComponent>): Component;
|
|
210
|
+
|
|
211
|
+
declare type Constructor = new (...args: any) => any;
|
|
212
|
+
|
|
177
213
|
/**
|
|
178
214
|
* Creates a router instance for a Vue application, equipped with methods for route handling, lifecycle hooks, and state management.
|
|
179
215
|
*
|
|
@@ -228,11 +264,9 @@ export declare class DuplicateParamsError extends Error {
|
|
|
228
264
|
*/
|
|
229
265
|
export declare type ExtractParamName<TParam extends string> = TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam;
|
|
230
266
|
|
|
231
|
-
declare type ExtractParamsFromPathString<TPath extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TPath extends `${
|
|
267
|
+
declare type ExtractParamsFromPathString<TPath extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TPath extends `${string}${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? MergeParams<{
|
|
232
268
|
[P in ExtractParamName<Param>]: ExtractPathParamType<Param, TParams>;
|
|
233
|
-
}, ExtractParamsFromPathString<Rest, TParams>> :
|
|
234
|
-
[P in ExtractParamName<Param>]: ExtractPathParamType<Param, TParams>;
|
|
235
|
-
} : Record<never, never>;
|
|
269
|
+
}, ExtractParamsFromPathString<Rest, TParams>> : Record<never, never>;
|
|
236
270
|
|
|
237
271
|
/**
|
|
238
272
|
* Extracts the actual type from a parameter type, handling getters, setters, and potential undefined values.
|
|
@@ -258,11 +292,9 @@ export declare type ExtractParamTypes<TParams extends Record<string, Param | und
|
|
|
258
292
|
*/
|
|
259
293
|
export declare type ExtractPathParamType<TParam extends string, TParams extends Record<string, Param | undefined>> = TParam extends `?${infer OptionalParam}` ? OptionalParam extends keyof TParams ? TParams[OptionalParam] | undefined : StringConstructor | undefined : TParam extends keyof TParams ? TParams[TParam] : StringConstructor;
|
|
260
294
|
|
|
261
|
-
declare type ExtractQueryParamsFromQueryString<TQuery extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TQuery extends `${string}
|
|
262
|
-
[P in ExtractParamName<Param>]: ExtractPathParamType<Param, TParams>;
|
|
263
|
-
}, ExtractQueryParamsFromQueryString<Rest, TParams>> : TQuery extends `${string}:${infer Param}` ? {
|
|
295
|
+
declare type ExtractQueryParamsFromQueryString<TQuery extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TQuery extends `${string}=${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? MergeParams<{
|
|
264
296
|
[P in ExtractParamName<Param>]: ExtractPathParamType<Param, TParams>;
|
|
265
|
-
} : Record<never, never>;
|
|
297
|
+
}, ExtractQueryParamsFromQueryString<Rest, TParams>> : Record<never, never>;
|
|
266
298
|
|
|
267
299
|
declare type ExtractRouteChildren<TRoute extends RouteProps> = TRoute extends ParentRouteProps ? TRoute['children'] extends Route[] ? TRoute['children'] : [] : [];
|
|
268
300
|
|
|
@@ -329,6 +361,30 @@ export declare function isParamGetter(value: Param): value is ParamGetter;
|
|
|
329
361
|
*/
|
|
330
362
|
export declare function isParentRoute(value: RouteProps): value is ParentRouteProps;
|
|
331
363
|
|
|
364
|
+
export declare function isParentRouteWithoutComponent(value: RouteProps): value is Omit<ParentRouteProps, 'component' | 'components'>;
|
|
365
|
+
|
|
366
|
+
export declare function isRoute(route: unknown): route is RouterRoute;
|
|
367
|
+
|
|
368
|
+
export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options: IsRouteOptions): route is RouterRoute<ResolvedRoute<RegisteredRouteMap[TRouteKey]>>;
|
|
369
|
+
|
|
370
|
+
declare type IsRouteOptions = {
|
|
371
|
+
exact?: boolean;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
declare const isRouterRouteSymbol: unique symbol;
|
|
375
|
+
|
|
376
|
+
export declare function isRouteWithComponent(value: RouteProps): value is RouteProps & WithComponent;
|
|
377
|
+
|
|
378
|
+
export declare function isRouteWithComponent(value: Readonly<RouteProps>): value is Readonly<RouteProps & WithComponent>;
|
|
379
|
+
|
|
380
|
+
export declare function isRouteWithComponent(value: DeepReadonly<RouteProps>): value is DeepReadonly<RouteProps & WithComponent>;
|
|
381
|
+
|
|
382
|
+
export declare function isRouteWithComponents(value: RouteProps): value is RouteProps & WithComponents;
|
|
383
|
+
|
|
384
|
+
export declare function isRouteWithComponents(value: Readonly<RouteProps>): value is Readonly<RouteProps & WithComponents>;
|
|
385
|
+
|
|
386
|
+
export declare function isRouteWithComponents(value: DeepReadonly<RouteProps>): value is DeepReadonly<RouteProps & WithComponents>;
|
|
387
|
+
|
|
332
388
|
declare type MakeOptional<T> = {
|
|
333
389
|
[P in WithOptionalProperties<T>]?: T[P];
|
|
334
390
|
} & {
|
|
@@ -400,9 +456,11 @@ declare type OnlyRequiredProperties<T> = {
|
|
|
400
456
|
[K in keyof T as Extract<T[K], undefined> extends never ? K : never]: T[K];
|
|
401
457
|
};
|
|
402
458
|
|
|
403
|
-
export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor;
|
|
459
|
+
export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON;
|
|
460
|
+
|
|
461
|
+
export declare type ParamEnd = typeof paramEnd;
|
|
404
462
|
|
|
405
|
-
declare
|
|
463
|
+
export declare const paramEnd = "]";
|
|
406
464
|
|
|
407
465
|
export declare type ParamExtras = {
|
|
408
466
|
invalid: (message?: string) => never;
|
|
@@ -417,10 +475,14 @@ export declare type ParamGetter<T = any> = (value: string, extras: ParamExtras)
|
|
|
417
475
|
|
|
418
476
|
export declare type ParamSetter<T = any> = (value: T, extras: ParamExtras) => string;
|
|
419
477
|
|
|
478
|
+
export declare type ParamStart = typeof paramStart;
|
|
479
|
+
|
|
480
|
+
export declare const paramStart = "[";
|
|
481
|
+
|
|
420
482
|
/**
|
|
421
483
|
* Represents properties common to parent routes in a route configuration, including hooks, path, and optional query parameters.
|
|
422
484
|
*/
|
|
423
|
-
export declare type ParentRouteProps = WithHooks & {
|
|
485
|
+
export declare type ParentRouteProps = Partial<WithComponent | WithComponents> & WithHooks & {
|
|
424
486
|
/**
|
|
425
487
|
* Name for route, used to create route keys and in navigation.
|
|
426
488
|
*/
|
|
@@ -441,19 +503,15 @@ export declare type ParentRouteProps = WithHooks & {
|
|
|
441
503
|
* Children routes, expected type comes from `createRoutes()`
|
|
442
504
|
*/
|
|
443
505
|
children: Routes;
|
|
444
|
-
/**
|
|
445
|
-
* Type alias for Vue components, which can be either synchronous or asynchronous components.
|
|
446
|
-
*/
|
|
447
|
-
component?: RouteComponent;
|
|
448
506
|
/**
|
|
449
507
|
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
450
508
|
*/
|
|
451
509
|
meta?: RouteMeta;
|
|
452
510
|
};
|
|
453
511
|
|
|
454
|
-
declare type Path<
|
|
455
|
-
path:
|
|
456
|
-
params: Identity<ExtractParamsFromPathString<
|
|
512
|
+
declare type Path<TPath extends string = any, TParams extends PathParams<TPath> = any> = {
|
|
513
|
+
path: TPath;
|
|
514
|
+
params: Identity<ExtractParamsFromPathString<TPath, TParams>>;
|
|
457
515
|
toString: () => string;
|
|
458
516
|
};
|
|
459
517
|
|
|
@@ -474,7 +532,7 @@ declare type Path<T extends string = any, P extends PathParams<T> = any> = {
|
|
|
474
532
|
* export const routes = createRoutes([
|
|
475
533
|
* {
|
|
476
534
|
* name: 'home',
|
|
477
|
-
* path: path('
|
|
535
|
+
* path: path('/[foo]', { foo: Number }),
|
|
478
536
|
* component: Home
|
|
479
537
|
* },
|
|
480
538
|
* ])
|
|
@@ -482,10 +540,14 @@ declare type Path<T extends string = any, P extends PathParams<T> = any> = {
|
|
|
482
540
|
*/
|
|
483
541
|
export declare function path<TPath extends string, TParams extends PathParams<TPath>>(path: TPath, params: Identity<TParams>): Path<TPath, TParams>;
|
|
484
542
|
|
|
485
|
-
declare type PathParams<
|
|
486
|
-
[K in keyof ExtractParamsFromPathString<
|
|
543
|
+
declare type PathParams<TPath extends string> = {
|
|
544
|
+
[K in keyof ExtractParamsFromPathString<TPath>]?: Param;
|
|
487
545
|
};
|
|
488
546
|
|
|
547
|
+
declare type Props<TComponent extends Component> = TComponent extends Constructor ? InstanceType<TComponent>['$props'] : TComponent extends AsyncComponentLoader<infer T extends Component> ? Props<T> : TComponent extends FunctionalComponent<infer T> ? T : never;
|
|
548
|
+
|
|
549
|
+
declare type PropsGetter<TComponent extends Component> = () => MaybePromise<Props<TComponent>>;
|
|
550
|
+
|
|
489
551
|
declare type Query<T extends string = any, P extends QueryParams<T> = any> = {
|
|
490
552
|
query: T;
|
|
491
553
|
params: Identity<ExtractQueryParamsFromQueryString<T, P>>;
|
|
@@ -509,7 +571,7 @@ declare type Query<T extends string = any, P extends QueryParams<T> = any> = {
|
|
|
509
571
|
* export const routes = createRoutes([
|
|
510
572
|
* {
|
|
511
573
|
* name: 'home',
|
|
512
|
-
* query: query('
|
|
574
|
+
* query: query('bar=[bar]', { bar: Boolean }),
|
|
513
575
|
* component: Home
|
|
514
576
|
* },
|
|
515
577
|
* ])
|
|
@@ -654,11 +716,6 @@ export declare type Route<TKey extends string | undefined = any, TPath extends s
|
|
|
654
716
|
disabled: TDisabled extends boolean ? TDisabled : false;
|
|
655
717
|
};
|
|
656
718
|
|
|
657
|
-
/**
|
|
658
|
-
* Type alias for Vue components, which can be either synchronous or asynchronous components.
|
|
659
|
-
*/
|
|
660
|
-
export declare type RouteComponent = Component | DefineComponent | AsyncComponentLoader;
|
|
661
|
-
|
|
662
719
|
declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesKey<TRoutes>> = RoutesMap<TRoutes>[TKey];
|
|
663
720
|
|
|
664
721
|
/**
|
|
@@ -838,22 +895,22 @@ declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
|
|
|
838
895
|
|
|
839
896
|
export declare const routerInjectionKey: InjectionKey<RegisteredRouter>;
|
|
840
897
|
|
|
841
|
-
export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent<
|
|
898
|
+
export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent<__VLS_TypePropsToRuntimeProps_2<{
|
|
842
899
|
to: Url | ToCallback;
|
|
843
|
-
} & RouterPushOptions>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<
|
|
900
|
+
} & RouterPushOptions>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_2<{
|
|
844
901
|
to: Url | ToCallback;
|
|
845
902
|
} & RouterPushOptions>>>, {}, {}>, Readonly<{
|
|
846
903
|
default?: ((props: {
|
|
847
904
|
resolved: string;
|
|
848
|
-
|
|
849
|
-
|
|
905
|
+
isMatch: boolean;
|
|
906
|
+
isExactMatch: boolean;
|
|
850
907
|
isExternal: boolean;
|
|
851
908
|
}) => unknown) | undefined;
|
|
852
909
|
}> & {
|
|
853
910
|
default?: ((props: {
|
|
854
911
|
resolved: string;
|
|
855
|
-
|
|
856
|
-
|
|
912
|
+
isMatch: boolean;
|
|
913
|
+
isExactMatch: boolean;
|
|
857
914
|
isExternal: boolean;
|
|
858
915
|
}) => unknown) | undefined;
|
|
859
916
|
}>;
|
|
@@ -897,11 +954,11 @@ export declare type RouterReject = (type: RouterRejectionType) => void;
|
|
|
897
954
|
|
|
898
955
|
declare type RouterRejection = Ref<null | {
|
|
899
956
|
type: RouterRejectionType;
|
|
900
|
-
component:
|
|
957
|
+
component: Component;
|
|
901
958
|
}>;
|
|
902
959
|
|
|
903
960
|
declare type RouterRejectionComponents = {
|
|
904
|
-
rejections?: Partial<Record<RouterRejectionType,
|
|
961
|
+
rejections?: Partial<Record<RouterRejectionType, Component>>;
|
|
905
962
|
};
|
|
906
963
|
|
|
907
964
|
export declare const routerRejectionKey: InjectionKey<RouterRejection>;
|
|
@@ -931,18 +988,35 @@ declare type RouterResolveOptions = {
|
|
|
931
988
|
declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = Omit<ResolvedRoute, 'params'> & Readonly<{
|
|
932
989
|
params: Writable<TRoute['params']>;
|
|
933
990
|
update: RouteUpdate<TRoute>;
|
|
991
|
+
[isRouterRouteSymbol]: true;
|
|
934
992
|
}>;
|
|
935
993
|
|
|
936
|
-
export declare const RouterView: __VLS_WithTemplateSlots<DefineComponent<
|
|
994
|
+
export declare const RouterView: __VLS_WithTemplateSlots<DefineComponent<__VLS_TypePropsToRuntimeProps<{
|
|
995
|
+
name?: string | undefined;
|
|
996
|
+
}>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
997
|
+
name?: string | undefined;
|
|
998
|
+
}>>>, {}, {}>, Readonly<{
|
|
937
999
|
default?: ((props: {
|
|
938
1000
|
route: RouterRoute;
|
|
939
|
-
component:
|
|
940
|
-
|
|
1001
|
+
component: Component;
|
|
1002
|
+
rejection: {
|
|
1003
|
+
type: "NotFound";
|
|
1004
|
+
component: Component;
|
|
1005
|
+
} | null;
|
|
1006
|
+
}) => VNode<RendererNode, RendererElement, {
|
|
1007
|
+
[key: string]: any;
|
|
1008
|
+
}>) | undefined;
|
|
941
1009
|
}> & {
|
|
942
1010
|
default?: ((props: {
|
|
943
1011
|
route: RouterRoute;
|
|
944
|
-
component:
|
|
945
|
-
|
|
1012
|
+
component: Component;
|
|
1013
|
+
rejection: {
|
|
1014
|
+
type: "NotFound";
|
|
1015
|
+
component: Component;
|
|
1016
|
+
} | null;
|
|
1017
|
+
}) => VNode<RendererNode, RendererElement, {
|
|
1018
|
+
[key: string]: any;
|
|
1019
|
+
}>) | undefined;
|
|
946
1020
|
}>;
|
|
947
1021
|
|
|
948
1022
|
/**
|
|
@@ -973,6 +1047,50 @@ declare type ToQuery<T extends string | Query | undefined> = T extends string ?
|
|
|
973
1047
|
|
|
974
1048
|
declare type Url = `http://${string}` | `https://${string}` | `/${string}` | '/';
|
|
975
1049
|
|
|
1050
|
+
export declare type UseLink = {
|
|
1051
|
+
/**
|
|
1052
|
+
* ResolvedRoute if matched. Same value as `router.find`
|
|
1053
|
+
*/
|
|
1054
|
+
route: Ref<ResolvedRoute | undefined>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Resolved URL with params interpolated and query applied. Same value as `router.resolve`.
|
|
1057
|
+
*/
|
|
1058
|
+
href: Ref<string>;
|
|
1059
|
+
/**
|
|
1060
|
+
* True if route matches current URL or is ancestor of route that matches current URL
|
|
1061
|
+
*/
|
|
1062
|
+
isMatch: Ref<boolean>;
|
|
1063
|
+
/**
|
|
1064
|
+
* True if route matches current URL. Route is the same as what's currently stored at `router.route`.
|
|
1065
|
+
*/
|
|
1066
|
+
isExactMatch: Ref<boolean>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Convenience method for executing `router.push` with route context passed in.
|
|
1069
|
+
*/
|
|
1070
|
+
push: (options?: RouterPushOptions) => Promise<void>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Convenience method for executing `router.replace` with route context passed in.
|
|
1073
|
+
*/
|
|
1074
|
+
replace: (options?: RouterReplaceOptions) => Promise<void>;
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* A composition to export much of the functionality that drives RouterLink component. Can be given route details to discover resolved URL,
|
|
1079
|
+
* or resolved URL to discover route details. Also exports some useful context about routes relationship to current URL and convenience methods
|
|
1080
|
+
* for navigating.
|
|
1081
|
+
*
|
|
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.
|
|
1084
|
+
* @param options - {@link RouterResolveOptions}Same options as router resolve.
|
|
1085
|
+
* @returns {UseLink} Reactive context values for as well as navigation methods.
|
|
1086
|
+
*
|
|
1087
|
+
*/
|
|
1088
|
+
export declare function useLink<TRouteKey extends string & keyof RegisteredRouteMap>(routeKey: MaybeRefOrGetter<TRouteKey>, ...args: UseLinkArgs<TRouteKey>): UseLink;
|
|
1089
|
+
|
|
1090
|
+
export declare function useLink(url: MaybeRefOrGetter<Url>): UseLink;
|
|
1091
|
+
|
|
1092
|
+
declare type UseLinkArgs<TSource extends string & keyof RegisteredRouteMap, TParams = RouteParamsByKey<RegisteredRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<RouterResolveOptions>] : [params: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<RouterResolveOptions>];
|
|
1093
|
+
|
|
976
1094
|
/**
|
|
977
1095
|
* A composition to access the router's rejection state.
|
|
978
1096
|
*
|
|
@@ -997,7 +1115,7 @@ export declare function useRejection(): RouterRejection;
|
|
|
997
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
|
|
998
1116
|
* if provided, throwing an error if the validation fails at any point during the component's lifecycle.
|
|
999
1117
|
*/
|
|
1000
|
-
export declare function useRoute<TRouteKey extends string & keyof RegisteredRouteMap>(routeKey: TRouteKey): RouterRoute<ResolvedRoute<RegisteredRouteMap[TRouteKey]>>;
|
|
1118
|
+
export declare function useRoute<TRouteKey extends string & keyof RegisteredRouteMap>(routeKey: TRouteKey, options?: UseRouteOptions): RouterRoute<ResolvedRoute<RegisteredRouteMap[TRouteKey]>>;
|
|
1001
1119
|
|
|
1002
1120
|
export declare function useRoute(): RouterRoute;
|
|
1003
1121
|
|
|
@@ -1014,6 +1132,10 @@ export declare class UseRouteInvalidError extends Error {
|
|
|
1014
1132
|
constructor(routeName: string, actualRouteName: string);
|
|
1015
1133
|
}
|
|
1016
1134
|
|
|
1135
|
+
export declare type UseRouteOptions = {
|
|
1136
|
+
exact?: boolean;
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1017
1139
|
/**
|
|
1018
1140
|
* A composition to access the registered router instance within a Vue component.
|
|
1019
1141
|
*
|
|
@@ -1023,6 +1145,20 @@ export declare class UseRouteInvalidError extends Error {
|
|
|
1023
1145
|
*/
|
|
1024
1146
|
export declare function useRouter(): RegisteredRouter;
|
|
1025
1147
|
|
|
1148
|
+
declare type WithComponent = {
|
|
1149
|
+
/**
|
|
1150
|
+
* A Vue component, which can be either synchronous or asynchronous components.
|
|
1151
|
+
*/
|
|
1152
|
+
component: Component;
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
declare type WithComponents = {
|
|
1156
|
+
/**
|
|
1157
|
+
* Multiple components for named views, which can be either synchronous or asynchronous components.
|
|
1158
|
+
*/
|
|
1159
|
+
components: Record<string, Component>;
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1026
1162
|
/**
|
|
1027
1163
|
* Defines route hooks that can be applied before entering, updating, or leaving a route, as well as after these events.
|
|
1028
1164
|
*/
|