import * as vue_router from 'vue-router'; import { NavigationGuard, Router, NavigationGuardReturn, RouteLocationNormalizedLoaded as RouteLocationNormalizedLoaded$1, LocationQuery, RouteRecordRaw } from 'vue-router'; import { App, EffectScope, ShallowRef } from 'vue'; /** * Retrieves the internal version of loaders. * @internal */ declare const LOADER_SET_KEY: unique symbol; /** * Retrieves the internal version of loader entries. * @internal */ declare const LOADER_ENTRIES_KEY: unique symbol; /** * Added to the loaders returned by `defineLoader()` to identify them. * Allows to extract exported useData() from a component. * @internal */ declare const IS_USE_DATA_LOADER_KEY: unique symbol; /** * Symbol used to save the pending location on the router. * @internal */ declare const PENDING_LOCATION_KEY: unique symbol; /** * Symbol used to know there is no value staged for the loader and that commit should be skipped. * @internal */ declare const STAGED_NO_VALUE: unique symbol; /** * Gives access to the current app and it's `runWithContext` method. * @internal */ declare const APP_KEY: unique symbol; /** * Gives access to an AbortController that aborts when the navigation is canceled. * @internal */ declare const ABORT_CONTROLLER_KEY: unique symbol; /** * Gives access to the navigation results when the navigation is aborted by the user within a data loader. * @internal */ declare const NAVIGATION_RESULTS_KEY: unique symbol; /** * Symbol used to save the initial data on the router. * @internal */ declare const IS_SSR_KEY: unique symbol; /** * Maybe a promise maybe not * @internal */ type _Awaitable = T | PromiseLike; /** * Options to initialize the data loader guard. */ interface SetupLoaderGuardOptions extends DataLoaderPluginOptions { /** * The Vue app instance. Used to access the `provide` and `inject` APIs. */ app: App; /** * The effect scope to use for the data loaders. */ effect: EffectScope; } /** * Possible values to change the result of a navigation within a loader * @internal */ type _DataLoaderRedirectResult = Exclude, Promise | Function | true | void | undefined>; /** * Possible values to change the result of a navigation within a loader. Can be returned from a data loader and will * appear in `selectNavigationResult`. If thrown, it will immediately cancel the navigation. It can only contain values * that cancel the navigation. * * @example * ```ts * export const useUserData = defineLoader(async (to) => { * const user = await fetchUser(to.params.id) * if (!user) { * return new NavigationResult('/404') * } * return user * }) * ``` */ declare class NavigationResult { readonly value: _DataLoaderRedirectResult; constructor(value: _DataLoaderRedirectResult); } /** * Data Loader plugin to add data loading support to Vue Router. * * @example * ```ts * const router = createRouter({ * routes, * history: createWebHistory(), * }) * * const app = createApp({}) * app.use(DataLoaderPlugin, { router }) * app.use(router) * ``` */ declare function DataLoaderPlugin(app: App, options: DataLoaderPluginOptions): void; /** * Options passed to the DataLoaderPlugin. */ interface DataLoaderPluginOptions { /** * The router instance. Adds the guards to it */ router: Router; isSSR?: boolean; /** * Called if any data loader returns a `NavigationResult` with an array of them. Should decide what is the outcome of * the data fetching guard. Note this isn't called if no data loaders return a `NavigationResult` or if an error is thrown. * @defaultValue `(results) => results[0].value` */ selectNavigationResult?: (results: NavigationResult[]) => _Awaitable>>; /** * List of _expected_ errors that shouldn't abort the navigation (for non-lazy loaders). Provide a list of * constructors that can be checked with `instanceof` or a custom function that returns `true` for expected errors. */ errors?: Array any> | ((reason?: unknown) => boolean); } /** * Map type for the entries used by data loaders. * @internal */ type _DefineLoaderEntryMap = DataLoaderEntryBase> = WeakMap; declare module 'vue-router' { interface Router { /** * The entries used by data loaders. Put on the router for convenience. * @internal */ [LOADER_ENTRIES_KEY]: _DefineLoaderEntryMap; /** * Pending navigation that is waiting for data loaders to resolve. * @internal */ [PENDING_LOCATION_KEY]: RouteLocationNormalizedLoaded | null; [APP_KEY]: App; [IS_SSR_KEY]: boolean; } interface RouteMeta { /** * The data loaders for a route record. Add any data loader to this array to have it called when the route is * navigated to. Note this is only needed when **not** using lazy components (`() => import('./pages/Home.vue')`) or * when not explicitly exporting data loaders from page components. */ loaders?: UseDataLoader[]; /** * Set of loaders for the current route. This is built once during navigation and is used to merge the loaders from * the lazy import in components or the `loaders` array in the route record. * @internal */ [LOADER_SET_KEY]?: Set; /** * The signal that is aborted when the navigation is canceled or an error occurs. * @internal */ [ABORT_CONTROLLER_KEY]?: AbortController; /** * The navigation results when the navigation is canceled by the user within a data loader. * @internal */ [NAVIGATION_RESULTS_KEY]?: NavigationResult[]; } } /** * @internal: data loaders authoring only. Use `getCurrentContext` instead. */ declare let currentContext: readonly [ entry: DataLoaderEntryBase, router: Router, route: RouteLocationNormalizedLoaded$1 ] | undefined | null; declare function getCurrentContext(): readonly [entry: DataLoaderEntryBase, router: Router, route: vue_router.RouteLocationNormalizedLoadedGeneric] | readonly []; /** * Sets the current context for data loaders. This allows for nested loaders to be aware of their parent context. * INTERNAL ONLY. * * @param context - the context to set * @internal */ declare function setCurrentContext(context?: typeof currentContext | readonly []): void; /** * Restore the current context after a promise is resolved. * @param promise - promise to wrap */ declare function withLoaderContext

>(promise: P): P; /** * Object and promise of the object itself. Used when we can await some of the properties of an object to be loaded. * @internal */ type _PromiseMerged = RawType & Promise; declare const assign: { (target: T, source: U): T & U; (target: T, source1: U, source2: V): T & U & V; (target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }; /** * Track the reads of a route and its properties * @internal * @param route - route to track */ declare function trackRoute(route: RouteLocationNormalizedLoaded$1): readonly [{ readonly hash: string; readonly params: vue_router.RouteParamsGeneric; readonly query: LocationQuery; readonly matched: vue_router.RouteLocationMatched[]; readonly name: vue_router.RouteRecordNameGeneric; readonly fullPath: string; readonly redirectedFrom: vue_router.RouteLocation | undefined; readonly path: string; readonly meta: vue_router.RouteMeta; }, Partial, Partial, { v: string | null; }]; /** * Returns `true` if `inner` is a subset of `outer`. Used to check if a tr * * @internal * @param outer - the bigger params * @param inner - the smaller params */ declare function isSubsetOf(inner: Partial, outer: LocationQuery): boolean; /** * Base type for a data loader entry. Each Data Loader has its own entry in the `loaderEntries` (accessible via `[LOADER_ENTRIES_KEY]`) map. */ interface DataLoaderEntryBase { /** * Data stored in the entry. */ data: ShallowRef<_DataMaybeLazy>; /** * Error if there was an error. */ error: ShallowRef; /** * Location the data was loaded for or `null` if the data is not loaded. */ to: RouteLocationNormalizedLoaded$1 | null; /** * Whether there is an ongoing request. */ isLoading: ShallowRef; options: DefineDataLoaderOptionsBase; /** * Called by the navigation guard when the navigation is duplicated. Should be used to reset pendingTo and pendingLoad and any other property that should be reset. */ resetPending: () => void; /** * The latest pending load. Allows to verify if the load is still valid when it resolves. */ pendingLoad: Promise | null; /** * The latest pending navigation's `to` route. Used to verify if the navigation is still valid when it resolves. */ pendingTo: RouteLocationNormalizedLoaded$1 | null; /** * Data that was staged by a loader. This is used to avoid showing the old data while the new data is loading. Calling * the internal `commit()` function will replace the data with the staged data. */ staged: Data | typeof STAGED_NO_VALUE; /** * Error that was staged by a loader. This is used to avoid showing the old error while the new data is loading. * Calling the internal `commit()` function will replace the error with the staged error. */ stagedError: any | null; /** * Other data loaders that depend on this one. This is used to invalidate the data when a dependency is invalidated. */ children: Set; /** * Commits the pending data to the entry. This is called by the navigation guard when all non-lazy loaders have * finished loading. It should be implemented by the loader. It **must be called** from the entry itself: * `entry.commit(to)`. */ commit(to: RouteLocationNormalizedLoaded$1): void; } interface DefineDataLoaderOptionsBase { /** * Whether the data should be lazy loaded without blocking the client side navigation or not. When set to true, the loader will no longer block the navigation and the returned composable can be called even * without having the data ready. * * @defaultValue `false` */ lazy?: isLazy | ((to: RouteLocationNormalizedLoaded$1, from?: RouteLocationNormalizedLoaded$1) => boolean); /** * Whether this loader should be awaited on the server side or not. Combined with the `lazy` option, this gives full * control over how to await for the data. * * @defaultValue `true` */ server?: boolean; /** * When the data should be committed to the entry. In the case of lazy loaders, the loader will try to commit the data * after all non-lazy loaders have finished loading, but it might not be able to if the lazy loader hasn't been * resolved yet. * * @see {@link DefineDataLoaderCommit} * @defaultValue `'after-load'` */ commit?: DefineDataLoaderCommit; /** * List of _expected_ errors that shouldn't abort the navigation (for non-lazy loaders). Provide a list of * constructors that can be checked with `instanceof` or a custom function that returns `true` for expected errors. */ errors?: Array any> | ((reason?: unknown) => boolean); } /** * When the data should be committed to the entry. * - `immediate`: the data is committed as soon as it is loaded. * - `after-load`: the data is committed after all non-lazy loaders have finished loading. */ type DefineDataLoaderCommit = 'immediate' | 'after-load'; interface DataLoaderContextBase { /** * Signal associated with the current navigation. It is aborted when the navigation is canceled or an error occurs. */ signal: AbortSignal | undefined; } /** * Data Loader composable returned by `defineLoader()`. * @see {@link DefineDataLoader} */ interface UseDataLoader { [IS_USE_DATA_LOADER_KEY]: true; /** * Data Loader composable returned by `defineLoader()`. * * @example * Returns the Data loader data, isLoading, error etc. Meant to be used in `setup()` or ` * ``` * * @example * It also returns a promise of the data when used in nested loaders. Note this `data` is **not a ref**. This is not meant to be used in `setup()` or `