@kitbag/router 0.26.0 → 0.27.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/dist/components/routerLink.d.ts +4 -4
- package/dist/components/routerProgress.d.ts +18 -0
- package/dist/components/routerProgressBar.d.ts +12 -0
- package/dist/compositions/useLink.d.ts +2 -2
- package/dist/compositions/useLink.spec-d.d.ts +1 -0
- package/dist/compositions/useNavigation.browser.spec.d.ts +1 -0
- package/dist/compositions/useNavigation.d.ts +5 -0
- package/dist/errors/contextRedirectError.d.ts +1 -2
- package/dist/errors/unreachableRouteError.d.ts +7 -0
- package/dist/kitbag-router.js +2100 -1711
- package/dist/kitbag-router.umd.cjs +2 -2
- package/dist/main.d.ts +25 -1
- package/dist/main.spec-d.d.ts +1 -0
- package/dist/services/addAlias.d.ts +19 -0
- package/dist/services/addAlias.spec-d.d.ts +1 -0
- package/dist/services/addAlias.spec.d.ts +1 -0
- package/dist/services/createCanonicalUrl.d.ts +14 -0
- package/dist/services/createCanonicalUrl.spec.d.ts +1 -0
- package/dist/services/createDataStore.d.ts +4 -0
- package/dist/services/createNavigationProgress.d.ts +49 -0
- package/dist/services/createNavigationProgress.spec.d.ts +1 -0
- package/dist/services/createNavigationSignals.d.ts +17 -0
- package/dist/services/createNavigationSignals.spec.d.ts +1 -0
- package/dist/services/createResolvedRoute.d.ts +10 -1
- package/dist/services/createRouteValueStore.d.ts +4 -0
- package/dist/services/createRouterAssets.d.ts +19 -0
- package/dist/services/createRouterHooks.d.ts +7 -2
- package/dist/services/createUniqueIdSequence.d.ts +0 -1
- package/dist/services/getInitialUrl.d.ts +2 -1
- package/dist/services/getMatchesForUrl.d.ts +4 -0
- package/dist/services/getRoutesForRouter.d.ts +3 -2
- package/dist/services/routeRegex.d.ts +6 -1
- package/dist/services/updateResolvedRoute.d.ts +7 -0
- package/dist/services/updateResolvedRoute.spec.d.ts +1 -0
- package/dist/services/withRouteMethods.d.ts +3 -3
- package/dist/tests/loaderPrefetch.browser.spec.d.ts +1 -0
- package/dist/tests/navigationProgress.spec.d.ts +1 -0
- package/dist/types/addAlias.d.ts +79 -0
- package/dist/types/callbackContext.d.ts +0 -5
- package/dist/types/createRouteOptions.d.ts +6 -2
- package/dist/types/hooks.d.ts +9 -5
- package/dist/types/navigation.d.ts +36 -0
- package/dist/types/prefetch.d.ts +6 -1
- package/dist/types/props.d.ts +1 -0
- package/dist/types/redirects.d.ts +4 -0
- package/dist/types/resolved.d.ts +22 -2
- package/dist/types/route.d.ts +2 -0
- package/dist/types/routeAlias.d.ts +41 -0
- package/dist/types/routeCallbackContext.d.ts +1 -0
- package/dist/types/routeWithMethods.d.ts +3 -2
- package/dist/types/routerLink.d.ts +1 -1
- package/dist/types/routerNavigationInternal.d.ts +29 -0
- package/dist/types/routerRoute.d.ts +5 -1
- package/dist/utilities/components.d.ts +6 -2
- package/dist/utilities/getRegexMatcher.d.ts +1 -0
- package/dist/utilities/getRegexMatcher.spec.d.ts +1 -0
- package/dist/utilities/percentEncoding.d.ts +10 -0
- package/dist/utilities/percentEncoding.spec.d.ts +1 -0
- package/package.json +6 -6
- package/dist/services/createNavigationIds.d.ts +0 -6
- /package/dist/{services/createNavigationIds.spec.d.ts → components/routerProgress.browser.spec.d.ts} +0 -0
package/dist/main.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { RegisteredRouter } from './types/register';
|
|
|
3
3
|
export type { WithHost, WithoutHost, WithParent, WithoutParent, CreateRouteOptions, PropsGetter, RouterViewPropsGetter, CreateRouteProps, ToRoute } from './types/createRouteOptions';
|
|
4
4
|
export type { RouteAddView, AddViewOptions, AddViewPropsGetter, AddViewPropsCallbackContext } from './types/addView';
|
|
5
5
|
export type { RouteAddLoader, AddLoaderOptions, LoaderGetter } from './types/addLoader';
|
|
6
|
+
export type { RouteAddAlias, AddAliasOptions } from './types/addAlias';
|
|
7
|
+
export type { AliasTransform, AliasTransformContext } from './types/routeAlias';
|
|
6
8
|
export type { RouteCallbackContext } from './types/routeCallbackContext';
|
|
7
9
|
export type { RouteViews } from './types/routeViews';
|
|
8
10
|
export type { RouteLoader, RouteLoaders } from './types/routeLoaders';
|
|
@@ -14,10 +16,12 @@ export * from './types/querySource';
|
|
|
14
16
|
export type { RouteRedirects } from './types/redirects';
|
|
15
17
|
export * from './types/register';
|
|
16
18
|
export type { Rejection, RejectionType, Rejections } from './types/rejection';
|
|
17
|
-
export
|
|
19
|
+
export { isResolvedRoute } from './types/resolved';
|
|
20
|
+
export type { ResolvedRoute, WithData, ResolvedRouteUnion, RouterResolvedRouteUnion } from './types/resolved';
|
|
18
21
|
export type { Route, CreatedRouteOptions } from './types/route';
|
|
19
22
|
export * from './types/router';
|
|
20
23
|
export * from './types/routerLink';
|
|
24
|
+
export type { RouterProgressProps } from './components/routerProgress';
|
|
21
25
|
export type { RouterPlugin, CreateRouterPluginOptions } from './types/routerPlugin';
|
|
22
26
|
export * from './types/routerPush';
|
|
23
27
|
export * from './types/routerPush';
|
|
@@ -30,6 +34,7 @@ export * from './types/routerRoute';
|
|
|
30
34
|
export * from './types/urlString';
|
|
31
35
|
export type { Url, CreateUrlOptions, ParseUrlOptions } from './types/url';
|
|
32
36
|
export * from './types/useLink';
|
|
37
|
+
export * from './types/navigation';
|
|
33
38
|
export { DuplicateParamsError } from './errors/duplicateParamsError';
|
|
34
39
|
export { LoaderDataAccessError } from './errors/loaderDataAccessError';
|
|
35
40
|
export { LoaderNameConflict } from './errors/loaderNameConflict';
|
|
@@ -39,6 +44,7 @@ export { PayloadValueError } from './errors/payloadValueError';
|
|
|
39
44
|
export { RouterNotInstalledError } from './errors/routerNotInstalledError';
|
|
40
45
|
export { UseRouteInvalidError } from './errors/useRouteInvalidError';
|
|
41
46
|
export { SsrOptionRequiredError } from './errors/ssrOptionRequiredError';
|
|
47
|
+
export { UnreachableRouteError } from './errors/unreachableRouteError';
|
|
42
48
|
export { createRoute } from './services/createRoute';
|
|
43
49
|
export { createRejection } from './services/createRejection';
|
|
44
50
|
export { createExternalRoute } from './services/createExternalRoute';
|
|
@@ -113,6 +119,15 @@ export declare const RouterView: RouterAssets<RegisteredRouter>['RouterView'];
|
|
|
113
119
|
* @group Components
|
|
114
120
|
*/
|
|
115
121
|
export declare const RouterLink: RouterAssets<RegisteredRouter>['RouterLink'];
|
|
122
|
+
/**
|
|
123
|
+
* A component to render a bar across the top of the page while a navigation is pending, filled by how
|
|
124
|
+
* much of the navigation's work has settled.
|
|
125
|
+
*
|
|
126
|
+
* @param props - The props to pass to the router progress component.
|
|
127
|
+
* @returns The router progress component.
|
|
128
|
+
* @group Components
|
|
129
|
+
*/
|
|
130
|
+
export declare const RouterProgress: RouterAssets<RegisteredRouter>['RouterProgress'];
|
|
116
131
|
/**
|
|
117
132
|
* A composition to access the current route or verify a specific route name within a Vue component.
|
|
118
133
|
* This function provides two overloads:
|
|
@@ -164,9 +179,18 @@ export declare const useLink: RouterAssets<RegisteredRouter>['useLink'];
|
|
|
164
179
|
* @group Compositions
|
|
165
180
|
*/
|
|
166
181
|
export declare const useRejection: RouterAssets<RegisteredRouter>['useRejection'];
|
|
182
|
+
/**
|
|
183
|
+
* A composition to access the navigation under way: whether one is pending, which routes it leaves and
|
|
184
|
+
* leads to, and how much of the work it waits on has settled.
|
|
185
|
+
*
|
|
186
|
+
* @returns {UseNavigation} Reactive state of the navigation under way.
|
|
187
|
+
* @group Compositions
|
|
188
|
+
*/
|
|
189
|
+
export declare const useNavigation: RouterAssets<RegisteredRouter>['useNavigation'];
|
|
167
190
|
declare module 'vue' {
|
|
168
191
|
interface GlobalComponents {
|
|
169
192
|
RouterView: typeof RouterView;
|
|
170
193
|
RouterLink: typeof RouterLink;
|
|
194
|
+
RouterProgress: typeof RouterProgress;
|
|
171
195
|
}
|
|
172
196
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AddAliasOptions } from '../types/addAlias';
|
|
2
|
+
import { AliasTransform, RouteAlias } from '../types/routeAlias';
|
|
3
|
+
import { CreatedRouteOptions, Route } from '../types/route';
|
|
4
|
+
/**
|
|
5
|
+
* The loose runtime signature of the `addAlias` method. Purposely wide: it returns Route rather than the
|
|
6
|
+
* refined chainable route `RouteAddAlias` describes.
|
|
7
|
+
*/
|
|
8
|
+
export type AddAlias = (options: AddAliasOptions, transform?: AliasTransform) => Route;
|
|
9
|
+
/**
|
|
10
|
+
* The aliases a nested route inherits: each of its parent's aliases combined with the route's own segment.
|
|
11
|
+
* The parent's own url is left out, since combined with the route's own segment it is the route's own url,
|
|
12
|
+
* not an alias.
|
|
13
|
+
*/
|
|
14
|
+
export declare function combineAliases(parent: Route, child: Route): RouteAlias[];
|
|
15
|
+
/**
|
|
16
|
+
* The aliases an `addAlias` call adds: the alias segment combined with every url the parent can be reached
|
|
17
|
+
* under, or standing alone when there is no parent to combine with.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createAliases(match: CreatedRouteOptions, options: AddAliasOptions, transform: AliasTransform | undefined): RouteAlias[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RouteAliasMatch } from '../types/routeAlias';
|
|
2
|
+
import { Url } from '../types/url';
|
|
3
|
+
import { UrlString } from '../types/urlString';
|
|
4
|
+
type CreateCanonicalUrlContext = {
|
|
5
|
+
route: Url;
|
|
6
|
+
params: Record<string, unknown>;
|
|
7
|
+
alias?: RouteAliasMatch;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Adds undeclared query values and a hash to the route's own url. Declared query keys (including
|
|
11
|
+
* omitted optional params) and a declared hash belong to the route and cannot be replaced by extras.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createCanonicalUrl(visitedUrl: UrlString, context: CreateCanonicalUrlContext): UrlString;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -39,6 +39,10 @@ export type DataStore = {
|
|
|
39
39
|
* What is known about a key, without waiting for it. Reactive, and readable during render.
|
|
40
40
|
*/
|
|
41
41
|
get: (key: string) => DataResult;
|
|
42
|
+
/**
|
|
43
|
+
* Aborts when the store is disposed, so a getter still running can stop work nothing will read.
|
|
44
|
+
*/
|
|
45
|
+
signal: AbortSignal;
|
|
42
46
|
/**
|
|
43
47
|
* Ends the store. Every value is rejected so that anything waiting on one resumes rather than staying
|
|
44
48
|
* suspended, then discarded.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ResolvedRoute } from '../types/resolved';
|
|
2
|
+
import { UseNavigation } from '../types/navigation';
|
|
3
|
+
/**
|
|
4
|
+
* The units of work one navigation waits on, counted as they are planned and as they settle. Every method
|
|
5
|
+
* is a no-op once the navigation is over or another has begun, so a unit settling late never counts
|
|
6
|
+
* against a later navigation.
|
|
7
|
+
*/
|
|
8
|
+
export type NavigationProgressTracker = {
|
|
9
|
+
/**
|
|
10
|
+
* Plans units that will be tracked later.
|
|
11
|
+
*/
|
|
12
|
+
expect: (count: number) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Counts each unit as settled when it does, however it settles. Only units already expected.
|
|
15
|
+
*/
|
|
16
|
+
track: (...units: Promise<unknown>[]) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Nothing more will be tracked. The navigation ends once every tracked unit has settled.
|
|
19
|
+
*/
|
|
20
|
+
close: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Ends the navigation as having gone nowhere, wiping its counts.
|
|
23
|
+
*/
|
|
24
|
+
abort: () => void;
|
|
25
|
+
};
|
|
26
|
+
type BeginContext = {
|
|
27
|
+
to: ResolvedRoute | null;
|
|
28
|
+
from: ResolvedRoute | null;
|
|
29
|
+
/**
|
|
30
|
+
* Units known before anything runs, so the total never shrinks a navigation's progress midway.
|
|
31
|
+
*/
|
|
32
|
+
expected: number;
|
|
33
|
+
/**
|
|
34
|
+
* An inert tracker counts nothing and leaves the state alone, for navigations with nothing to show.
|
|
35
|
+
*/
|
|
36
|
+
inert?: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type NavigationProgress = UseNavigation & {
|
|
39
|
+
/**
|
|
40
|
+
* Begins counting a navigation, discarding whatever the navigation before it still had outstanding.
|
|
41
|
+
*/
|
|
42
|
+
begin: (context: BeginContext) => NavigationProgressTracker;
|
|
43
|
+
/**
|
|
44
|
+
* Aborts the navigation being counted, if any.
|
|
45
|
+
*/
|
|
46
|
+
stop: () => void;
|
|
47
|
+
};
|
|
48
|
+
export declare function createNavigationProgress(): NavigationProgress;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which navigation is under way. Only the latest navigation counts: beginning another makes the one before
|
|
3
|
+
* it moot, and so does stopping the router.
|
|
4
|
+
*/
|
|
5
|
+
export type NavigationSignals = {
|
|
6
|
+
/**
|
|
7
|
+
* Begins a navigation, aborting the one under way. The controller aborts once a later navigation begins
|
|
8
|
+
* or the router stops, and is already aborted for a navigation begun after the router stopped. The
|
|
9
|
+
* navigation aborts it itself when it ends without committing.
|
|
10
|
+
*/
|
|
11
|
+
begin: () => AbortController;
|
|
12
|
+
/**
|
|
13
|
+
* Aborts the navigation under way, and every one begun afterwards.
|
|
14
|
+
*/
|
|
15
|
+
stop: () => void;
|
|
16
|
+
};
|
|
17
|
+
export declare function createNavigationSignals(): NavigationSignals;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { RouterResolveOptions } from '../types/routerResolve';
|
|
2
2
|
import { ResolvedRoute } from '../types/resolved';
|
|
3
3
|
import { Route } from '../types/route';
|
|
4
|
-
|
|
4
|
+
import { RouteAliasMatch } from '../types/routeAlias';
|
|
5
|
+
type CreateResolvedRouteOptions = RouterResolveOptions & {
|
|
6
|
+
/**
|
|
7
|
+
* The alias the route was matched through, which is what `href` is built from instead of the route's
|
|
8
|
+
* own url.
|
|
9
|
+
*/
|
|
10
|
+
alias?: RouteAliasMatch;
|
|
11
|
+
};
|
|
12
|
+
export declare function createResolvedRoute(route: Route, params?: Record<string, unknown>, options?: CreateResolvedRouteOptions): ResolvedRoute;
|
|
13
|
+
export {};
|
|
@@ -20,6 +20,10 @@ export type RouteValueResponse = CallbackContextSuccess | CallbackContextPush |
|
|
|
20
20
|
export type RouteValueResponses = {
|
|
21
21
|
props: Promise<RouteValueResponse>;
|
|
22
22
|
loaders: Promise<RouteValueResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Each value on its own as it settles, for whoever counts them.
|
|
25
|
+
*/
|
|
26
|
+
values: Promise<unknown>[];
|
|
23
27
|
};
|
|
24
28
|
/**
|
|
25
29
|
* A store of a route's values, whichever store that is.
|
|
@@ -2,6 +2,7 @@ import { Router, RouterRoutes, RouterRejections } from '../types/router';
|
|
|
2
2
|
import { InjectionKey } from 'vue';
|
|
3
3
|
import { createRouterView } from '../components/routerView';
|
|
4
4
|
import { createRouterLink } from '../components/routerLink';
|
|
5
|
+
import { createRouterProgress } from '../components/routerProgress';
|
|
5
6
|
import { createUseRoute } from '../compositions/useRoute';
|
|
6
7
|
import { createUseRouter } from '../compositions/useRouter';
|
|
7
8
|
import { createUseQueryValue } from '../compositions/useQueryValue';
|
|
@@ -9,6 +10,7 @@ import { createUseLink } from '../compositions/useLink';
|
|
|
9
10
|
import { createIsRoute } from '../guards/routes';
|
|
10
11
|
import { AddBeforeLeaveHook, AddBeforeUpdateHook, AddAfterLeaveHook, AddAfterUpdateHook } from '../types/hooks';
|
|
11
12
|
import { createUseRejection } from '../compositions/useRejection';
|
|
13
|
+
import { createUseNavigation } from '../compositions/useNavigation';
|
|
12
14
|
export type RouterAssets<TRouter extends Router> = {
|
|
13
15
|
/**
|
|
14
16
|
* Registers a hook that is called before a route is left. Must be called from setup.
|
|
@@ -70,6 +72,15 @@ export type RouterAssets<TRouter extends Router> = {
|
|
|
70
72
|
* @group Components
|
|
71
73
|
*/
|
|
72
74
|
RouterLink: ReturnType<typeof createRouterLink<TRouter>>;
|
|
75
|
+
/**
|
|
76
|
+
* A component to render a bar across the top of the page while a navigation is pending, filled by how
|
|
77
|
+
* much of the navigation's work has settled.
|
|
78
|
+
*
|
|
79
|
+
* @param props - The props to pass to the router progress component.
|
|
80
|
+
* @returns The router progress component.
|
|
81
|
+
* @group Components
|
|
82
|
+
*/
|
|
83
|
+
RouterProgress: ReturnType<typeof createRouterProgress<TRouter>>;
|
|
73
84
|
/**
|
|
74
85
|
* A composition to access the current route or verify a specific route name within a Vue component.
|
|
75
86
|
* This function provides two overloads:
|
|
@@ -121,6 +132,14 @@ export type RouterAssets<TRouter extends Router> = {
|
|
|
121
132
|
* @group Compositions
|
|
122
133
|
*/
|
|
123
134
|
useRejection: ReturnType<typeof createUseRejection<TRouter>>;
|
|
135
|
+
/**
|
|
136
|
+
* A composition to access the navigation under way: whether one is pending, which routes it leaves and
|
|
137
|
+
* leads to, and how much of the work it waits on has settled.
|
|
138
|
+
*
|
|
139
|
+
* @returns {UseNavigation} Reactive state of the navigation under way.
|
|
140
|
+
* @group Compositions
|
|
141
|
+
*/
|
|
142
|
+
useNavigation: ReturnType<typeof createUseNavigation<TRouter>>;
|
|
124
143
|
};
|
|
125
144
|
export declare function createRouterAssets<TRouter extends Router>(router: TRouter): RouterAssets<TRouter>;
|
|
126
145
|
export declare function createRouterAssets<TRouter extends Router>(routerKey: InjectionKey<TRouter>): RouterAssets<TRouter>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AddGlobalHooks, AddComponentHook, AfterHookRunner, BeforeHookRunner, AddBeforeEnterHook, AddBeforeUpdateHook, AddBeforeLeaveHook, AddAfterEnterHook, AddAfterUpdateHook, AddAfterLeaveHook, ErrorHookRunner, AddErrorHook, RejectionHookRunner, AddRejectionHook } from '../types/hooks';
|
|
2
2
|
import { HasVueAppStore } from './createVueAppStore';
|
|
3
|
-
|
|
3
|
+
import { RedirectStatus } from '../types/router';
|
|
4
|
+
export declare const getRouterHooksKey: (routerKey: import('vue').InjectionKey<import('../types/router').Router>) => import('vue').InjectionKey<RouterHooks>;
|
|
4
5
|
export type RouterHooks = HasVueAppStore & {
|
|
5
6
|
runBeforeRouteHooks: BeforeHookRunner;
|
|
6
7
|
runAfterRouteHooks: AfterHookRunner;
|
|
@@ -17,4 +18,8 @@ export type RouterHooks = HasVueAppStore & {
|
|
|
17
18
|
onError: AddErrorHook;
|
|
18
19
|
onRejection: AddRejectionHook;
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
+
type RouterHooksOptions = {
|
|
22
|
+
redirectStatus: RedirectStatus;
|
|
23
|
+
};
|
|
24
|
+
export declare function createRouterHooks({ redirectStatus }: RouterHooksOptions): RouterHooks;
|
|
25
|
+
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RouterHistoryMode } from './createRouterHistory';
|
|
2
|
+
export declare function getInitialUrl(initialUrl?: string, mode?: RouterHistoryMode): string;
|
|
@@ -4,5 +4,9 @@ import { ParseUrlOptions } from '../types/url';
|
|
|
4
4
|
type MatchOptions = {
|
|
5
5
|
state?: Partial<unknown>;
|
|
6
6
|
} & ParseUrlOptions;
|
|
7
|
+
/**
|
|
8
|
+
* Every route's own url is tried before any alias, so an alias never outranks another route's own url
|
|
9
|
+
* regardless of the order the routes were defined in.
|
|
10
|
+
*/
|
|
7
11
|
export declare function getMatchForUrl(routes: Routes, url: string, options?: MatchOptions): ResolvedRoute | undefined;
|
|
8
12
|
export {};
|
|
@@ -4,12 +4,13 @@ import { BuiltInRejectionType, Rejection, RejectionInternal } from '../types/rej
|
|
|
4
4
|
import { RouterOptions } from '../types/router';
|
|
5
5
|
/**
|
|
6
6
|
* Takes in routes and plugins and returns a list of routes with the base route inserted if provided.
|
|
7
|
-
* Also checks for duplicate names in the routes.
|
|
7
|
+
* Also checks for duplicate names and unreachable paths in the routes.
|
|
8
8
|
*
|
|
9
9
|
* @throws {DuplicateNamesError} If there are duplicate names in the routes.
|
|
10
|
+
* @throws {UnreachableRouteError} If a named route's path does not start with `/`.
|
|
10
11
|
*/
|
|
11
12
|
export declare function getRoutesForRouter(routes: Routes | Routes[], plugins?: RouterPlugin[], options?: RouterOptions): {
|
|
12
|
-
routes: (import('../
|
|
13
|
+
routes: (import('../types/url').Url & {
|
|
13
14
|
id: string;
|
|
14
15
|
matches: import('../types/route').CreatedRouteOptions[];
|
|
15
16
|
name: string;
|
|
@@ -7,13 +7,18 @@ export declare const regexCatchAll = "[^/]*";
|
|
|
7
7
|
export declare const regexGreedyCatchAll = ".*";
|
|
8
8
|
export declare const regexCaptureAll = "([^/]*)";
|
|
9
9
|
export declare const regexGreedyCaptureAll = "(.*)";
|
|
10
|
+
export declare function escapeRegExp(string: string): string;
|
|
10
11
|
export declare function splitByMatches(string: string, regexp: RegExp): string[];
|
|
11
12
|
export declare function generateRouteHostRegexPattern(host: string): RegExp;
|
|
12
13
|
export declare function generateRoutePathRegexPattern(path: string): RegExp;
|
|
13
14
|
export declare function generateRouteHashRegexPattern(hash: string): RegExp;
|
|
14
15
|
export declare function generateRouteQueryRegexPatterns(query: string): RegExp[];
|
|
15
16
|
export declare function replaceParamSyntaxWithCatchAlls(value: string): string;
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* A pattern that captures one param and matches the rest of the part literally, with every other param
|
|
19
|
+
* replaced by a catch-all.
|
|
20
|
+
*/
|
|
21
|
+
export declare function replaceParamWithCaptureGroupAndEscapeRest(part: UrlPart, paramName: string): string;
|
|
17
22
|
export declare function isOptionalParamSyntax(value: string): boolean;
|
|
18
23
|
export declare function isRequiredParamSyntax(value: string): boolean;
|
|
19
24
|
export declare function isGreedyParamSyntax(value: string): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ResolvedRoute } from '../types/resolved';
|
|
2
|
+
import { RouterResolveOptions } from '../types/routerResolve';
|
|
3
|
+
/**
|
|
4
|
+
* Applies query, hash, and state to an already resolved route the same way a push with those options
|
|
5
|
+
* changes the url. Query values are appended, hash and state values override.
|
|
6
|
+
*/
|
|
7
|
+
export declare function updateResolvedRoute(route: ResolvedRoute, options: RouterResolveOptions): ResolvedRoute;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Route } from '../types/route';
|
|
2
2
|
/**
|
|
3
|
-
* Attaches the chainable, immutable route methods — `addView` and `
|
|
4
|
-
* route's own (last) match and returns a new route with the methods
|
|
5
|
-
* route it was called on, and chaining one never drops
|
|
3
|
+
* Attaches the chainable, immutable route methods — `addView`, `addLoader`, and `addAlias`. Each call
|
|
4
|
+
* rebuilds the route's own (last) match, or its aliases, and returns a new route with the methods
|
|
5
|
+
* re-attached, so none mutates the route it was called on, and chaining one never drops another.
|
|
6
6
|
*/
|
|
7
7
|
export declare function withRouteMethods<TRoute extends Route>(route: TRoute): TRoute;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { UrlPart, UrlQueryPart } from '../services/withParams';
|
|
2
|
+
import { AliasTransform } from './routeAlias';
|
|
3
|
+
import { CreatedRouteOptions } from './route';
|
|
4
|
+
import { RouteWithMethods } from './routeWithMethods';
|
|
5
|
+
import { ToUrl, Url, UrlParamsReading, UrlParamsWriting } from './url';
|
|
6
|
+
import { LastInArray } from './utilities';
|
|
7
|
+
/**
|
|
8
|
+
* The url an alias matches, in the same shapes `createRoute` takes. An alias declares its whole url:
|
|
9
|
+
* nothing is taken from the route's own path, query, or hash.
|
|
10
|
+
*/
|
|
11
|
+
export type AddAliasOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* Path part of the alias.
|
|
14
|
+
*/
|
|
15
|
+
path?: string | UrlPart | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Query (aka search) part of the alias.
|
|
18
|
+
*/
|
|
19
|
+
query?: string | UrlQueryPart | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Hash part of the alias.
|
|
22
|
+
*/
|
|
23
|
+
hash?: string | UrlPart | undefined;
|
|
24
|
+
};
|
|
25
|
+
type PathPart = string | UrlPart | undefined;
|
|
26
|
+
type QueryPart = string | UrlQueryPart | undefined;
|
|
27
|
+
type SegmentPath<TMatches extends CreatedRouteOptions[]> = LastInArray<TMatches> extends {
|
|
28
|
+
path: infer TPath extends PathPart;
|
|
29
|
+
} ? TPath : undefined;
|
|
30
|
+
type SegmentQuery<TMatches extends CreatedRouteOptions[]> = LastInArray<TMatches> extends {
|
|
31
|
+
query: infer TQuery extends QueryPart;
|
|
32
|
+
} ? TQuery : undefined;
|
|
33
|
+
type SegmentHash<TMatches extends CreatedRouteOptions[]> = LastInArray<TMatches> extends {
|
|
34
|
+
hash: infer THash extends PathPart;
|
|
35
|
+
} ? THash : undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The url of the route's own segment: its own path, query, and hash without any ancestors. An alias
|
|
38
|
+
* stands in for this segment, so its params are what an alias transform has to produce.
|
|
39
|
+
*/
|
|
40
|
+
type SegmentUrl<TMatches extends CreatedRouteOptions[]> = CreatedRouteOptions[] extends TMatches ? Url : ToUrl<{
|
|
41
|
+
path: SegmentPath<TMatches>;
|
|
42
|
+
query: SegmentQuery<TMatches>;
|
|
43
|
+
hash: SegmentHash<TMatches>;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* The params an alias parses from a url, as read.
|
|
47
|
+
*/
|
|
48
|
+
type AliasParams<TOptions extends AddAliasOptions> = UrlParamsReading<ToUrl<TOptions>>;
|
|
49
|
+
/**
|
|
50
|
+
* The params the route's own segment declares, as written. What an alias transform returns.
|
|
51
|
+
*/
|
|
52
|
+
type SegmentParams<TMatches extends CreatedRouteOptions[]> = UrlParamsWriting<SegmentUrl<TMatches>>;
|
|
53
|
+
/**
|
|
54
|
+
* The transform argument for `addAlias`. Optional only when the alias's params already satisfy the
|
|
55
|
+
* segment's, since matched values pass straight through then. A shape mismatch has to be resolved at
|
|
56
|
+
* declaration time: parsing walks the params declared on the pattern doing the parsing, so a mismatch
|
|
57
|
+
* would silently read a promised param as undefined instead of failing.
|
|
58
|
+
*/
|
|
59
|
+
type AddAliasArgs<TOptions extends AddAliasOptions, TMatches extends CreatedRouteOptions[]> = AliasParams<TOptions> extends SegmentParams<TMatches> ? [transform?: AliasTransform<AliasParams<TOptions>, SegmentParams<TMatches>>] : [transform: AliasTransform<AliasParams<TOptions>, SegmentParams<TMatches>>];
|
|
60
|
+
/**
|
|
61
|
+
* Adds an alias to a route. Chainable to register several.
|
|
62
|
+
*/
|
|
63
|
+
export type RouteAddAlias<TUrl extends Url = Url, TMatches extends CreatedRouteOptions[] = CreatedRouteOptions[]> = {
|
|
64
|
+
/**
|
|
65
|
+
* Adds a url the route also matches. The address bar keeps the alias; the route resolves as if its own
|
|
66
|
+
* url had matched. Aliases only match inbound urls: links and navigation always target the route's own
|
|
67
|
+
* url.
|
|
68
|
+
*
|
|
69
|
+
* The alias stands in for this route's own path, query, and hash, and composes with any aliases of the
|
|
70
|
+
* route's ancestors. It declares its own params, typed the same way a route's are, and any param the
|
|
71
|
+
* route's own segment declares that the alias does not is the transform's to supply.
|
|
72
|
+
*
|
|
73
|
+
* @param options - The alias's `path`, `query`, and `hash`, each taking what `createRoute` does.
|
|
74
|
+
* @param transform - Maps the alias's params into the params this route's own segment declares.
|
|
75
|
+
* Required unless the alias's params already satisfy them.
|
|
76
|
+
*/
|
|
77
|
+
addAlias: <const TOptions extends AddAliasOptions>(options: TOptions, ...args: AddAliasArgs<TOptions, TMatches>) => RouteWithMethods<TUrl, TMatches>;
|
|
78
|
+
};
|
|
79
|
+
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RedirectStatus } from './router';
|
|
2
1
|
import { RouterPush } from './routerPush';
|
|
3
2
|
export type CallbackContextSuccess = {
|
|
4
3
|
status: 'SUCCESS';
|
|
@@ -10,10 +9,6 @@ export type CallbackContextPush = {
|
|
|
10
9
|
export type CallbackContextRedirect = {
|
|
11
10
|
status: 'REDIRECT';
|
|
12
11
|
to: Parameters<RouterPush>;
|
|
13
|
-
/**
|
|
14
|
-
* The status the redirect declared, or undefined to use the router's `redirectStatus`.
|
|
15
|
-
*/
|
|
16
|
-
redirectStatus: RedirectStatus | undefined;
|
|
17
12
|
};
|
|
18
13
|
export type CallbackContextReject = {
|
|
19
14
|
status: 'REJECT';
|
|
@@ -2,7 +2,7 @@ import { Component } from 'vue';
|
|
|
2
2
|
import { Param } from './paramTypes';
|
|
3
3
|
import { PrefetchConfig } from './prefetch';
|
|
4
4
|
import { RouteMeta } from './register';
|
|
5
|
-
import { Route } from './route';
|
|
5
|
+
import { Route, RouteInternal } from './route';
|
|
6
6
|
import { ResolvedRoute, WithData } from './resolved';
|
|
7
7
|
import { ComponentProps } from '../services/component';
|
|
8
8
|
import { PropsCallbackContext } from './props';
|
|
@@ -153,5 +153,9 @@ export type ToRouteUrl<TOptions extends CreateRouteOptions> = TOptions extends {
|
|
|
153
153
|
*/
|
|
154
154
|
export type ToRouteMatches<TOptions extends CreateRouteOptions, TProps> = ToMatches<TOptions, CreateRouteProps<TOptions> extends TProps ? undefined : TProps>;
|
|
155
155
|
export type ToRoute<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined = undefined> = CreateRouteOptions extends TOptions ? Route : Route<ToRouteUrl<TOptions>, ToRouteMatches<TOptions, TProps>>;
|
|
156
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Nests a route under its parent. A hoisted route keeps everything of its parent's except the url: its own
|
|
158
|
+
* url stands alone and it inherits none of the parent's aliases.
|
|
159
|
+
*/
|
|
160
|
+
export declare function combineRoutes(parent: Route, child: Route, hoisted?: boolean): Route & RouteInternal;
|
|
157
161
|
export {};
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { RouteContext, RouteContextToRejection, RouteContextToRoute } from './ro
|
|
|
10
10
|
import { RouterAbort } from './routerAbort';
|
|
11
11
|
import { CallbackContextAbort, CallbackContextPush, CallbackContextRedirect, CallbackContextReject, CallbackContextSuccess } from './callbackContext';
|
|
12
12
|
import { RouteUpdate } from './routeUpdate';
|
|
13
|
+
import { NavigationProgressTracker } from '../services/createNavigationProgress';
|
|
13
14
|
export declare function getHooks(value: Record<string, unknown> | undefined | null): Hooks[];
|
|
14
15
|
export declare function combineHooks(parent: Route, child: Route): Hooks[];
|
|
15
16
|
export type InternalRouteHooks<TRoute extends Route = Route, TContext extends RouteContext[] | undefined = undefined> = {
|
|
@@ -89,6 +90,7 @@ type AfterHookContext<TRoute extends Route, TRoutes extends Routes, TRejections
|
|
|
89
90
|
push: RouterPush<TRoutes>;
|
|
90
91
|
replace: RouterReplace<TRoutes>;
|
|
91
92
|
update: RouteUpdate<ResolvedRouteUnion<TRoute>>;
|
|
93
|
+
signal: AbortSignal;
|
|
92
94
|
};
|
|
93
95
|
type BeforeHookContext<TRouteTo extends Route, TRoutes extends Routes, TRejections extends Rejections> = {
|
|
94
96
|
reject: RouterReject<TRejections>;
|
|
@@ -96,6 +98,7 @@ type BeforeHookContext<TRouteTo extends Route, TRoutes extends Routes, TRejectio
|
|
|
96
98
|
replace: RouterReplace<TRoutes>;
|
|
97
99
|
update: RouteUpdate<ResolvedRouteUnion<TRouteTo>>;
|
|
98
100
|
abort: RouterAbort;
|
|
101
|
+
signal: AbortSignal;
|
|
99
102
|
};
|
|
100
103
|
export type BeforeEnterHookContext<TRoutes extends Routes = Routes, TRejections extends Rejections = Rejections, TRouteTo extends Route = TRoutes[number], TRouteFrom extends Route = TRoutes[number]> = BeforeHookContext<TRouteTo, TRoutes, TRejections> & {
|
|
101
104
|
from: ResolvedRouteUnion<TRouteFrom> | null;
|
|
@@ -129,14 +132,15 @@ export type AfterLeaveHook<TRoutes extends Routes = Routes, TRejections extends
|
|
|
129
132
|
export type AddAfterLeaveHook<TRoutes extends Routes = Routes, TRejections extends Rejections = Rejections, TRouteTo extends Route = TRoutes[number], TRouteFrom extends Route = TRoutes[number]> = (hook: AfterLeaveHook<TRoutes, TRejections, TRouteTo, TRouteFrom>) => HookRemove;
|
|
130
133
|
export type BeforeHookResponse = CallbackContextSuccess | CallbackContextPush | CallbackContextRedirect | CallbackContextReject | CallbackContextAbort;
|
|
131
134
|
export type AfterHookResponse = CallbackContextSuccess | CallbackContextPush | CallbackContextReject;
|
|
132
|
-
export type
|
|
135
|
+
export type HookRunnerContext<TRoutes extends Routes = Routes> = {
|
|
133
136
|
to: RouterResolvedRouteUnion<TRoutes> | null;
|
|
134
137
|
from: RouterResolvedRouteUnion<TRoutes> | null;
|
|
138
|
+
signal: AbortSignal;
|
|
139
|
+
};
|
|
140
|
+
export type BeforeHookRunner = <TRoutes extends Routes>(context: HookRunnerContext<TRoutes> & {
|
|
141
|
+
progress?: NavigationProgressTracker;
|
|
135
142
|
}) => Promise<BeforeHookResponse>;
|
|
136
|
-
export type AfterHookRunner = <TRoutes extends Routes>(context:
|
|
137
|
-
to: RouterResolvedRouteUnion<TRoutes> | null;
|
|
138
|
-
from: RouterResolvedRouteUnion<TRoutes> | null;
|
|
139
|
-
}) => Promise<AfterHookResponse>;
|
|
143
|
+
export type AfterHookRunner = <TRoutes extends Routes>(context: HookRunnerContext<TRoutes>) => Promise<AfterHookResponse>;
|
|
140
144
|
export type RejectionHookContext<TRoutes extends Routes = Routes, TRouteTo extends Route = TRoutes[number], TRouteFrom extends Route = TRoutes[number]> = {
|
|
141
145
|
to: ResolvedRouteUnion<TRouteTo> | null;
|
|
142
146
|
from: ResolvedRouteUnion<TRouteFrom> | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { ResolvedRoute } from './resolved';
|
|
3
|
+
/**
|
|
4
|
+
* The navigation under way, if any, and how far it has come. A navigation is under way from the moment it
|
|
5
|
+
* is asked for until the route it leads to has everything it renders with, or it is rejected, aborted, or
|
|
6
|
+
* superseded. Its progress is counted in the units of work it waits on: its before hooks, its props getters
|
|
7
|
+
* and loaders, and the async components it renders. Every unit counts the same.
|
|
8
|
+
*/
|
|
9
|
+
export type UseNavigation = {
|
|
10
|
+
/**
|
|
11
|
+
* True while a navigation is under way.
|
|
12
|
+
*/
|
|
13
|
+
pending: ComputedRef<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* The route the navigation under way leads to. Null when idle, or when the url matches no route.
|
|
16
|
+
*/
|
|
17
|
+
to: ComputedRef<ResolvedRoute | null>;
|
|
18
|
+
/**
|
|
19
|
+
* The route the navigation under way leaves. Null when idle, or for the first navigation.
|
|
20
|
+
*/
|
|
21
|
+
from: ComputedRef<ResolvedRoute | null>;
|
|
22
|
+
/**
|
|
23
|
+
* How many units have settled so far. Equal to `total` once a navigation reaches its route, and zero
|
|
24
|
+
* once one ends by being rejected or aborted.
|
|
25
|
+
*/
|
|
26
|
+
settled: ComputedRef<number>;
|
|
27
|
+
/**
|
|
28
|
+
* How many units the navigation waits on in all. Known up front except for before hooks, which are
|
|
29
|
+
* added as they start.
|
|
30
|
+
*/
|
|
31
|
+
total: ComputedRef<number>;
|
|
32
|
+
/**
|
|
33
|
+
* The share of units settled, between 0 and 1. Zero while idle.
|
|
34
|
+
*/
|
|
35
|
+
progress: ComputedRef<number>;
|
|
36
|
+
};
|
package/dist/types/prefetch.d.ts
CHANGED
|
@@ -11,10 +11,15 @@ export type PrefetchConfigOptions = {
|
|
|
11
11
|
*/
|
|
12
12
|
components?: boolean | PrefetchStrategy;
|
|
13
13
|
/**
|
|
14
|
-
* When true
|
|
14
|
+
* When true route props will be prefetched
|
|
15
15
|
* @default false
|
|
16
16
|
*/
|
|
17
17
|
props?: boolean | PrefetchStrategy;
|
|
18
|
+
/**
|
|
19
|
+
* When true route loaders will be prefetched
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
loaders?: boolean | PrefetchStrategy;
|
|
18
23
|
};
|
|
19
24
|
/**
|
|
20
25
|
* Determines what assets are prefetched. A boolean enables or disables all prefetching.
|
package/dist/types/props.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type PropsCallbackContext<TRoute extends Route = Route, TOptions extends
|
|
|
17
17
|
push: RouterPush<[TRoute] | ExtractRouteContextRoutes<TOptions>>;
|
|
18
18
|
replace: RouterReplace<[TRoute] | ExtractRouteContextRoutes<TOptions>>;
|
|
19
19
|
update: RouteUpdate<ResolvedRoute<TRoute>>;
|
|
20
|
+
signal: AbortSignal;
|
|
20
21
|
parent: PropsCallbackParent<TOptions['parent']>;
|
|
21
22
|
};
|
|
22
23
|
export type PropsCallbackParent<TParent extends Route | undefined = Route | undefined> = Route | undefined extends TParent ? undefined | {
|
|
@@ -16,6 +16,10 @@ export type RouteRedirects<TRoute extends Route = Route> = {
|
|
|
16
16
|
};
|
|
17
17
|
type RedirectHookContext<TRoutes extends Routes> = {
|
|
18
18
|
replace: RouterReplace<TRoutes>;
|
|
19
|
+
/**
|
|
20
|
+
* The router's status for a redirect that does not declare its own.
|
|
21
|
+
*/
|
|
22
|
+
redirectStatus: RedirectStatus;
|
|
19
23
|
};
|
|
20
24
|
export type RedirectHook<TRoutes extends Routes = Routes, TRouteTo extends Route = TRoutes[number]> = (to: ResolvedRouteUnion<TRouteTo>, context: RedirectHookContext<TRoutes>) => MaybePromise<void>;
|
|
21
25
|
export type RouteRedirectCallback<TRouteTo extends Route = Route, TRouteFrom extends Route = Route> = (params: UrlParamsReading<TRouteFrom>) => UrlParamsWriting<TRouteTo>;
|