@kitbag/router 0.2.0 → 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 +130 -20
- package/dist/kitbag-router.js +863 -792
- 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
|
@@ -6,13 +6,19 @@ import { DefineComponent } from 'vue';
|
|
|
6
6
|
import { ExtractPropTypes } from 'vue';
|
|
7
7
|
import { FunctionalComponent } from 'vue';
|
|
8
8
|
import { InjectionKey } from 'vue';
|
|
9
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
9
10
|
import { Plugin as Plugin_2 } from 'vue';
|
|
10
11
|
import { PropType } from 'vue';
|
|
11
12
|
import { PublicProps } from 'vue';
|
|
12
13
|
import { Ref } from 'vue';
|
|
14
|
+
import { RendererElement } from 'vue';
|
|
15
|
+
import { RendererNode } from 'vue';
|
|
16
|
+
import { VNode } from 'vue';
|
|
13
17
|
|
|
14
18
|
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
15
19
|
|
|
20
|
+
declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T;
|
|
21
|
+
|
|
16
22
|
declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
17
23
|
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
18
24
|
type: PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
@@ -22,6 +28,15 @@ declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
|
22
28
|
};
|
|
23
29
|
};
|
|
24
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
|
+
|
|
25
40
|
declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
26
41
|
new (): {
|
|
27
42
|
$slots: S;
|
|
@@ -128,7 +143,7 @@ declare type BuiltInRejectionType = typeof builtInRejections[number];
|
|
|
128
143
|
/**
|
|
129
144
|
* Represents properties for child routes, including required component, name, and path.
|
|
130
145
|
*/
|
|
131
|
-
export declare type ChildRouteProps = WithHooks & {
|
|
146
|
+
export declare type ChildRouteProps = (WithComponent | WithComponents) & WithHooks & {
|
|
132
147
|
/**
|
|
133
148
|
* Name for route, used to create route keys and in navigation.
|
|
134
149
|
*/
|
|
@@ -145,10 +160,6 @@ export declare type ChildRouteProps = WithHooks & {
|
|
|
145
160
|
* Query (aka search) part of URL.
|
|
146
161
|
*/
|
|
147
162
|
query?: string | Query;
|
|
148
|
-
/**
|
|
149
|
-
* A Vue component, which can be either synchronous or asynchronous components.
|
|
150
|
-
*/
|
|
151
|
-
component: Component;
|
|
152
163
|
/**
|
|
153
164
|
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
154
165
|
*/
|
|
@@ -350,6 +361,30 @@ export declare function isParamGetter(value: Param): value is ParamGetter;
|
|
|
350
361
|
*/
|
|
351
362
|
export declare function isParentRoute(value: RouteProps): value is ParentRouteProps;
|
|
352
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
|
+
|
|
353
388
|
declare type MakeOptional<T> = {
|
|
354
389
|
[P in WithOptionalProperties<T>]?: T[P];
|
|
355
390
|
} & {
|
|
@@ -447,7 +482,7 @@ export declare const paramStart = "[";
|
|
|
447
482
|
/**
|
|
448
483
|
* Represents properties common to parent routes in a route configuration, including hooks, path, and optional query parameters.
|
|
449
484
|
*/
|
|
450
|
-
export declare type ParentRouteProps = WithHooks & {
|
|
485
|
+
export declare type ParentRouteProps = Partial<WithComponent | WithComponents> & WithHooks & {
|
|
451
486
|
/**
|
|
452
487
|
* Name for route, used to create route keys and in navigation.
|
|
453
488
|
*/
|
|
@@ -468,10 +503,6 @@ export declare type ParentRouteProps = WithHooks & {
|
|
|
468
503
|
* Children routes, expected type comes from `createRoutes()`
|
|
469
504
|
*/
|
|
470
505
|
children: Routes;
|
|
471
|
-
/**
|
|
472
|
-
* A Vue component, which can be either synchronous or asynchronous components.
|
|
473
|
-
*/
|
|
474
|
-
component?: Component;
|
|
475
506
|
/**
|
|
476
507
|
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
477
508
|
*/
|
|
@@ -864,22 +895,22 @@ declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
|
|
|
864
895
|
|
|
865
896
|
export declare const routerInjectionKey: InjectionKey<RegisteredRouter>;
|
|
866
897
|
|
|
867
|
-
export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent<
|
|
898
|
+
export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent<__VLS_TypePropsToRuntimeProps_2<{
|
|
868
899
|
to: Url | ToCallback;
|
|
869
|
-
} & RouterPushOptions>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<
|
|
900
|
+
} & RouterPushOptions>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_2<{
|
|
870
901
|
to: Url | ToCallback;
|
|
871
902
|
} & RouterPushOptions>>>, {}, {}>, Readonly<{
|
|
872
903
|
default?: ((props: {
|
|
873
904
|
resolved: string;
|
|
874
|
-
|
|
875
|
-
|
|
905
|
+
isMatch: boolean;
|
|
906
|
+
isExactMatch: boolean;
|
|
876
907
|
isExternal: boolean;
|
|
877
908
|
}) => unknown) | undefined;
|
|
878
909
|
}> & {
|
|
879
910
|
default?: ((props: {
|
|
880
911
|
resolved: string;
|
|
881
|
-
|
|
882
|
-
|
|
912
|
+
isMatch: boolean;
|
|
913
|
+
isExactMatch: boolean;
|
|
883
914
|
isExternal: boolean;
|
|
884
915
|
}) => unknown) | undefined;
|
|
885
916
|
}>;
|
|
@@ -957,18 +988,35 @@ declare type RouterResolveOptions = {
|
|
|
957
988
|
declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = Omit<ResolvedRoute, 'params'> & Readonly<{
|
|
958
989
|
params: Writable<TRoute['params']>;
|
|
959
990
|
update: RouteUpdate<TRoute>;
|
|
991
|
+
[isRouterRouteSymbol]: true;
|
|
960
992
|
}>;
|
|
961
993
|
|
|
962
|
-
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<{
|
|
963
999
|
default?: ((props: {
|
|
964
1000
|
route: RouterRoute;
|
|
965
1001
|
component: Component;
|
|
966
|
-
|
|
1002
|
+
rejection: {
|
|
1003
|
+
type: "NotFound";
|
|
1004
|
+
component: Component;
|
|
1005
|
+
} | null;
|
|
1006
|
+
}) => VNode<RendererNode, RendererElement, {
|
|
1007
|
+
[key: string]: any;
|
|
1008
|
+
}>) | undefined;
|
|
967
1009
|
}> & {
|
|
968
1010
|
default?: ((props: {
|
|
969
1011
|
route: RouterRoute;
|
|
970
1012
|
component: Component;
|
|
971
|
-
|
|
1013
|
+
rejection: {
|
|
1014
|
+
type: "NotFound";
|
|
1015
|
+
component: Component;
|
|
1016
|
+
} | null;
|
|
1017
|
+
}) => VNode<RendererNode, RendererElement, {
|
|
1018
|
+
[key: string]: any;
|
|
1019
|
+
}>) | undefined;
|
|
972
1020
|
}>;
|
|
973
1021
|
|
|
974
1022
|
/**
|
|
@@ -999,6 +1047,50 @@ declare type ToQuery<T extends string | Query | undefined> = T extends string ?
|
|
|
999
1047
|
|
|
1000
1048
|
declare type Url = `http://${string}` | `https://${string}` | `/${string}` | '/';
|
|
1001
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
|
+
|
|
1002
1094
|
/**
|
|
1003
1095
|
* A composition to access the router's rejection state.
|
|
1004
1096
|
*
|
|
@@ -1023,7 +1115,7 @@ export declare function useRejection(): RouterRejection;
|
|
|
1023
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
|
|
1024
1116
|
* if provided, throwing an error if the validation fails at any point during the component's lifecycle.
|
|
1025
1117
|
*/
|
|
1026
|
-
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]>>;
|
|
1027
1119
|
|
|
1028
1120
|
export declare function useRoute(): RouterRoute;
|
|
1029
1121
|
|
|
@@ -1040,6 +1132,10 @@ export declare class UseRouteInvalidError extends Error {
|
|
|
1040
1132
|
constructor(routeName: string, actualRouteName: string);
|
|
1041
1133
|
}
|
|
1042
1134
|
|
|
1135
|
+
export declare type UseRouteOptions = {
|
|
1136
|
+
exact?: boolean;
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1043
1139
|
/**
|
|
1044
1140
|
* A composition to access the registered router instance within a Vue component.
|
|
1045
1141
|
*
|
|
@@ -1049,6 +1145,20 @@ export declare class UseRouteInvalidError extends Error {
|
|
|
1049
1145
|
*/
|
|
1050
1146
|
export declare function useRouter(): RegisteredRouter;
|
|
1051
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
|
+
|
|
1052
1162
|
/**
|
|
1053
1163
|
* Defines route hooks that can be applied before entering, updating, or leaving a route, as well as after these events.
|
|
1054
1164
|
*/
|