Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unplugin-vue-router

Package Overview
Dependencies
Maintainers
0
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unplugin-vue-router - npm Package Compare versions

Comparing version 0.9.1 to 0.10.0

dist/chunk-JAQZ7GSU.js

96

client.d.ts
declare module 'vue-router/auto-routes' {
import type { RouteRecordRaw } from 'vue-router'
import type { RouteRecordRaw, Router } from 'vue-router'

@@ -8,30 +8,27 @@ /**

export const routes: RouteRecordRaw[]
}
declare module 'unplugin-vue-router/types' {
import type { RouteNamedMap } from 'vue-router/auto-routes'
export interface TypesConfig {
RouteNamedMap: RouteNamedMap
}
/**
* Setups hot module replacement for routes.
* @param router - The router instance
* @example
* ```ts
* import { createRouter, createWebHistory } from 'vue-router'
* import { routes, handleHotUpdate } from 'vue-router/auto-routes'
* const router = createRouter({
* history: createWebHistory(),
* routes,
* })
* if (import.meta.hot) {
* handleHotUpdate(router)
* }
* ```
*/
export function handleHotUpdate(router: Router): void
}
declare module 'vue-router' {
import type {
NavigationGuardTyped,
NavigationGuardWithThisTyped,
RouteLocationNormalizedLoadedTypedList,
_RouterTyped,
RouterLinkTyped,
} from 'unplugin-vue-router/types'
import type { RouteNamedMap } from 'vue-router/auto-routes'
import type { RouteNamedMap } from 'vue-router/auto-routes'
export interface TypesConfig {
beforeRouteEnter: NavigationGuardWithThisTyped<undefined, RouteNamedMap>
beforeRouteUpdate: NavigationGuardTyped<RouteNamedMap>
beforeRouteLeave: NavigationGuardTyped<RouteNamedMap>
$route: RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[keyof RouteNamedMap]
$router: _RouterTyped<RouteNamedMap>
RouterLink: RouterLinkTyped<RouteNamedMap>
RouteNamedMap: RouteNamedMap
}

@@ -41,52 +38,6 @@ }

declare module 'vue-router/auto' {
import type { RouteNamedMap } from 'vue-router/auto-routes'
import type {
_RouterTyped,
_RouterOptions,
RouteLocationNormalizedLoadedTypedList,
NavigationGuardTyped,
RouterLinkPropsTyped,
RouterLinkTyped,
UseLinkFnTyped,
} from 'unplugin-vue-router/types'
// reexport all types that are not augmented by unplugin-vue-router
export * from 'vue-router'
// Augmented types to override the ones exported by vue-router
export type {
Router,
RouteLocationNormalized,
RouteRecordName,
RouteLocationNormalizedLoaded,
RouteLocation,
RouteLocationAsRelativePath,
RouteLocationRaw,
RouteLocationResolved,
RouteParams,
RouteParamsRaw,
NavigationGuard,
NavigationGuardWithThis,
} from 'unplugin-vue-router/types'
/**
* @deprecated use `Router` instead. This type will be a different one in the next major version.
*/
export type RouterTyped = _RouterTyped<RouteNamedMap>
export function useRouter(): _RouterTyped<RouteNamedMap>
export function useRoute<
Name extends keyof RouteNamedMap = keyof RouteNamedMap,
>(name?: Name): RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[Name]
export const useLink: UseLinkFnTyped<RouteNamedMap>
export function onBeforeRouteLeave(
guard: NavigationGuardTyped<RouteNamedMap>
): void
export function onBeforeRouteUpdate(
guard: NavigationGuardTyped<RouteNamedMap>
): void
export const RouterLink: RouterLinkTyped<RouteNamedMap>
export const RouterLinkProps: RouterLinkPropsTyped<RouteNamedMap>
export function createRouter(
options: _RouterOptions
): _RouterTyped<RouteNamedMap>
// TODO: deprecate vue-router/auto
export {

@@ -104,2 +55,7 @@ // Experimental Data Fetching

// Make the macros globally available
declare global {
const definePage: (typeof import('unplugin-vue-router/runtime'))['definePage']
}
export {}

@@ -1,2 +0,2 @@

import { RouteRecordName, RouteLocationNormalizedLoaded } from 'unplugin-vue-router/types';
import { RouteMap, RouteLocationNormalizedLoaded } from 'vue-router';
import { DefineLoaderFn, DefineDataLoaderOptionsBase, DataLoaderContextBase, UseDataLoader } from 'unplugin-vue-router/runtime';

@@ -15,3 +15,3 @@

*/
declare function defineBasicLoader<Name extends RouteRecordName, Data, isLazy extends boolean>(name: Name, loader: DefineLoaderFn<Data, DataLoaderContext, RouteLocationNormalizedLoaded<Name>>, options?: DefineDataLoaderOptions<isLazy>): UseDataLoaderBasic<isLazy, Data>;
declare function defineBasicLoader<Name extends keyof RouteMap, Data, isLazy extends boolean>(name: Name, loader: DefineLoaderFn<Data, DataLoaderContext, RouteLocationNormalizedLoaded<Name>>, options?: DefineDataLoaderOptions<isLazy>): UseDataLoaderBasic<isLazy, Data>;
declare function defineBasicLoader<Data, isLazy extends boolean>(loader: DefineLoaderFn<Data, DataLoaderContext, RouteLocationNormalizedLoaded>, options?: DefineDataLoaderOptions<isLazy>): UseDataLoaderBasic<isLazy, Data>;

@@ -18,0 +18,0 @@ interface DefineDataLoaderOptions<isLazy extends boolean> extends DefineDataLoaderOptionsBase<isLazy> {

// src/data-loaders/defineLoader.ts
import { useRoute, useRouter } from "vue-router";
import {
useRoute,
useRouter
} from "vue-router";
import {
ABORT_CONTROLLER_KEY,

@@ -5,0 +8,0 @@ APP_KEY,

@@ -1,3 +0,2 @@

import { LocationQuery } from 'vue-router';
import { RouteRecordName, RouteLocationNormalizedLoaded } from 'unplugin-vue-router/types';
import { RouteMap, RouteLocationNormalizedLoaded, LocationQuery } from 'vue-router';
import { DefineDataLoaderOptionsBase, DefineLoaderFn, DataLoaderContextBase, UseDataLoaderResult, UseDataLoader, _PromiseMerged, NavigationResult, DataLoaderEntryBase } from 'unplugin-vue-router/runtime';

@@ -18,5 +17,5 @@ import { ShallowRef } from 'vue';

*/
declare function defineColadaLoader<Name extends RouteRecordName, Data, isLazy extends boolean>(name: Name, options: DefineDataColadaLoaderOptions<isLazy, Name, Data>): UseDataLoaderColada<isLazy, Data>;
declare function defineColadaLoader<Data, isLazy extends boolean>(options: DefineDataColadaLoaderOptions<isLazy, RouteRecordName, Data>): UseDataLoaderColada<isLazy, Data>;
interface DefineDataColadaLoaderOptions<isLazy extends boolean, Name extends RouteRecordName, Data> extends DefineDataLoaderOptionsBase<isLazy>, Omit<UseQueryOptions<unknown>, 'query' | 'key'> {
declare function defineColadaLoader<Name extends keyof RouteMap, Data, isLazy extends boolean>(name: Name, options: DefineDataColadaLoaderOptions<isLazy, Name, Data>): UseDataLoaderColada<isLazy, Data>;
declare function defineColadaLoader<Data, isLazy extends boolean>(options: DefineDataColadaLoaderOptions<isLazy, keyof RouteMap, Data>): UseDataLoaderColada<isLazy, Data>;
interface DefineDataColadaLoaderOptions<isLazy extends boolean, Name extends keyof RouteMap, Data> extends DefineDataLoaderOptionsBase<isLazy>, Omit<UseQueryOptions<unknown>, 'query' | 'key'> {
/**

@@ -23,0 +22,0 @@ * Key associated with the data and passed to pinia colada

import * as esbuild from 'esbuild';
import { O as Options } from './options-EuMjkncO.js';
import { O as Options } from './types-B3fGzmzY.js';
import 'vue-router';

@@ -4,0 +4,0 @@

import {
src_default
} from "./chunk-YHQCGS2V.js";
} from "./chunk-JAQZ7GSU.js";
import "./chunk-HWA3WM2K.js";

@@ -5,0 +5,0 @@ import "./chunk-6F4PWJZI.js";

import * as unplugin from 'unplugin';
import { R as ResolvedOptions, S as ServerContext, O as Options } from './options-EuMjkncO.js';
export { D as DEFAULT_OPTIONS, E as EditableTreeNode, T as TreeNode, b as TreeNodeValueParam, d as TreeNodeValueStatic, c as createTreeNodeValue, g as getFileBasedRouteName, a as getPascalCaseRouteName } from './options-EuMjkncO.js';
export { NavigationGuard, NavigationGuardReturn, NavigationGuardTyped, NavigationGuardWithThis, NavigationGuardWithThisTyped, NavigationHookAfterTyped, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, RouteLocation, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativePath, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteNamedMap, RouteParams, RouteParamsRaw, RouteRecordInfo, RouteRecordName, Router, RouterLinkPropsTyped, RouterLinkTyped, TypesConfig, UseLinkFnTyped, _RouteMapGeneric, _RouterOptions, _RouterTyped, _UseLinkReturnTyped } from './types.js';
import { R as ResolvedOptions, S as ServerContext, O as Options } from './types-B3fGzmzY.js';
export { D as DEFAULT_OPTIONS, E as EditableTreeNode, T as TreeNode, b as TreeNodeValueParam, d as TreeNodeValueStatic, c as createTreeNodeValue, g as getFileBasedRouteName, a as getPascalCaseRouteName } from './types-B3fGzmzY.js';
import 'vue-router';
import 'vue';

@@ -8,0 +6,0 @@ declare function createRoutesContext(options: ResolvedOptions): {

@@ -7,3 +7,3 @@ import {

src_default
} from "./chunk-YHQCGS2V.js";
} from "./chunk-JAQZ7GSU.js";
import {

@@ -10,0 +10,0 @@ DEFAULT_OPTIONS,

@@ -1,2 +0,2 @@

export { D as DEFAULT_OPTIONS, O as Options, R as ResolvedOptions, j as RoutesFolder, e as RoutesFolderOption, f as RoutesFolderOptionResolved, S as ServerContext, h as _OverridableOption, i as _RoutesFolder, m as mergeAllExtensions, k as resolveOptions, r as resolveOverridableOption } from './options-EuMjkncO.js';
export { D as DEFAULT_OPTIONS, O as Options, R as ResolvedOptions, i as RoutesFolder, e as RoutesFolderOption, f as RoutesFolderOptionResolved, S as ServerContext, _ as _OverridableOption, h as _RoutesFolder, m as mergeAllExtensions, j as resolveOptions, r as resolveOverridableOption } from './types-B3fGzmzY.js';
import 'vue-router';
import * as rollup from 'rollup';
import { O as Options } from './options-EuMjkncO.js';
import { O as Options } from './types-B3fGzmzY.js';
import 'vue-router';

@@ -4,0 +4,0 @@

import {
src_default
} from "./chunk-YHQCGS2V.js";
} from "./chunk-JAQZ7GSU.js";
import "./chunk-HWA3WM2K.js";

@@ -5,0 +5,0 @@ import "./chunk-6F4PWJZI.js";

@@ -1,5 +0,4 @@

import { NavigationGuard, Router as Router$1, LocationQuery, RouteRecordRaw } from 'vue-router';
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';
import * as unplugin_vue_router_types from 'unplugin-vue-router/types';
import { Router, RouteLocationNormalizedLoaded as RouteLocationNormalizedLoaded$1 } from 'unplugin-vue-router/types';

@@ -120,3 +119,3 @@ /**

*/
router: Router | Router$1;
router: Router;
isSSR?: boolean;

@@ -128,3 +127,3 @@ /**

*/
selectNavigationResult?: (results: NavigationResult[]) => _Awaitable<Exclude<ReturnType<NavigationGuard>, Function | Promise<unknown>>>;
selectNavigationResult?: (results: NavigationResult[]) => _Awaitable<Exclude<NavigationGuardReturn, Function | Promise<unknown>>>;
}

@@ -187,3 +186,3 @@

] | undefined | null;
declare function getCurrentContext(): readonly [entry: DataLoaderEntryBase<boolean, unknown>, router: unplugin_vue_router_types._RouterTyped<RouteNamedMap>, route: RouteNamedMap] | readonly [];
declare function getCurrentContext(): readonly [entry: DataLoaderEntryBase<boolean, unknown>, router: Router, route: vue_router.RouteLocationNormalizedLoadedGeneric] | readonly [];
declare function setCurrentContext(context: typeof currentContext | readonly []): void;

@@ -211,3 +210,13 @@ /**

*/
declare function trackRoute(route: RouteLocationNormalizedLoaded$1): readonly [any, any, any, {
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.RouteLocationGeneric | undefined;
readonly path: string;
readonly meta: vue_router.RouteMeta;
}, Partial<vue_router.RouteParamsGeneric>, Partial<LocationQuery>, {
v: string | null;

@@ -214,0 +223,0 @@ }];

@@ -143,69 +143,65 @@ // src/data-loaders/navigation-guard.ts

});
const removeDataLoaderGuard = router.beforeResolve(
(to) => {
const loaders = Array.from(to.meta[LOADER_SET_KEY]);
setCurrentContext([]);
return Promise.all(
loaders.map((loader) => {
const { server, lazy } = loader._.options;
if (!server && isSSR) {
return;
}
const ret = effect.run(
() => app.runWithContext(
() => loader._.load(to, router)
)
);
return !isSSR && lazy ? void 0 : (
// return the non-lazy loader to commit changes after all loaders are done
ret
);
})
).then(() => {
if (to.meta[NAVIGATION_RESULTS_KEY].length) {
return selectNavigationResult(to.meta[NAVIGATION_RESULTS_KEY]);
const removeDataLoaderGuard = router.beforeResolve((to) => {
const loaders = Array.from(to.meta[LOADER_SET_KEY]);
setCurrentContext([]);
return Promise.all(
loaders.map((loader) => {
const { server, lazy } = loader._.options;
if (!server && isSSR) {
return;
}
}).catch(
(error) => error instanceof NavigationResult ? error.value : (
// let the error propagate to router.onError()
// we use never because the rejection means we never resolve a value and using anything else
// will not be valid from the navigation guard's perspective
Promise.reject(error)
const ret = effect.run(
() => app.runWithContext(
() => loader._.load(to, router)
)
);
return !isSSR && lazy ? void 0 : (
// return the non-lazy loader to commit changes after all loaders are done
ret
);
})
).then(() => {
if (to.meta[NAVIGATION_RESULTS_KEY].length) {
return selectNavigationResult(to.meta[NAVIGATION_RESULTS_KEY]);
}
}).catch(
(error) => error instanceof NavigationResult ? error.value : (
// let the error propagate to router.onError()
// we use never because the rejection means we never resolve a value and using anything else
// will not be valid from the navigation guard's perspective
Promise.reject(error)
)
);
});
const removeAfterEach = router.afterEach((to, _from, failure) => {
if (failure) {
to.meta[ABORT_CONTROLLER_KEY]?.abort(failure);
if (
// NOTE: using a smaller version to cutoff some bytes
isNavigationFailure(
failure,
16
/* NavigationFailureType.duplicated */
)
);
}
);
const removeAfterEach = router.afterEach(
(to, _from, failure) => {
if (failure) {
to.meta[ABORT_CONTROLLER_KEY]?.abort(failure);
if (
// NOTE: using a smaller version to cutoff some bytes
isNavigationFailure(
failure,
16
/* NavigationFailureType.duplicated */
)
) {
for (const loader of to.meta[LOADER_SET_KEY]) {
const entry = loader._.getEntry(router);
entry.resetPending();
}
) {
for (const loader of to.meta[LOADER_SET_KEY]) {
const entry = loader._.getEntry(router);
entry.resetPending();
}
} else {
for (const loader of to.meta[LOADER_SET_KEY]) {
const { commit, lazy } = loader._.options;
if (commit === "after-load") {
const entry = loader._.getEntry(router);
if (entry && (!lazy || !entry.isLoading.value)) {
entry.commit(to);
}
}
} else {
for (const loader of to.meta[LOADER_SET_KEY]) {
const { commit, lazy } = loader._.options;
if (commit === "after-load") {
const entry = loader._.getEntry(router);
if (entry && (!lazy || !entry.isLoading.value)) {
entry.commit(to);
}
}
}
if (router[PENDING_LOCATION_KEY] === to) {
router[PENDING_LOCATION_KEY] = null;
}
}
);
if (router[PENDING_LOCATION_KEY] === to) {
router[PENDING_LOCATION_KEY] = null;
}
});
const removeOnError = router.onError((error, to) => {

@@ -212,0 +208,0 @@ to.meta[ABORT_CONTROLLER_KEY]?.abort(error);

@@ -1,326 +0,2 @@

import { RouteParamsRaw, RouteParams, RouteMeta, RouteLocationNormalized, RouteRecordName, RouteLocationNormalizedLoaded, RouteQueryAndHash, RouteLocationOptions, RouteLocation, NavigationGuardNext, NavigationFailure, Router, RouterOptions, RouteRecordRaw, RouterLinkProps, RouteLocationRaw } from 'vue-router';
import { L as LiteralStringUnion, _ as _Awaitable } from './options-EuMjkncO.js';
export { E as EditableTreeNode, O as Options, T as TreeNode, b as TreeNodeValueParam, d as TreeNodeValueStatic } from './options-EuMjkncO.js';
import { ShallowRef, AllowedComponentProps, ComponentCustomProps, VNodeProps, UnwrapRef, VNode, ComputedRef, Ref } from 'vue';
/**
* Helper type to define a Typed `RouteRecord`
* @see {@link RouteRecord}
*/
interface RouteRecordInfo<Name extends string = string, Path extends string = string, ParamsRaw extends RouteParamsRaw = RouteParamsRaw, Params extends RouteParams = RouteParams, Meta extends RouteMeta = RouteMeta> {
name: Name;
path: Path;
paramsRaw: ParamsRaw;
params: Params;
meta: Meta;
}
/**
* Generic version of RouteNamedMap.
* @internal
*/
type _RouteMapGeneric = Record<string, RouteRecordInfo>;
/**
* Allows using types that are generated at build-time. **ONLY FOR INTERNAL USAGE**.
*
* @internal
*/
interface TypesConfig {
}
/**
* Convenience type to get the typed RouteMap or a generic one if not provided.
*/
type RouteNamedMap = TypesConfig extends Record<'RouteNamedMap', infer RouteNamedMap> ? RouteNamedMap : Record<string, RouteRecordInfo>;
type _RouteRecordName = keyof RouteNamedMap;
interface RouteLocationNormalizedTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalized {
name: Extract<Name, RouteRecordName>;
params: RouteMap[Name]['params'];
}
type RouteLocationNormalizedTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = {
[N in keyof RouteMap]: RouteLocationNormalizedTyped<RouteMap, N>;
};
interface RouteLocationNormalizedLoadedTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalizedLoaded {
name: Extract<Name, RouteRecordName>;
params: RouteMap[Name]['params'];
}
type RouteLocationNormalizedLoadedTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = {
[N in keyof RouteMap]: RouteLocationNormalizedLoadedTyped<RouteMap, N>;
};
interface RouteLocationAsRelativeTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteQueryAndHash, RouteLocationOptions {
name?: Name;
params?: RouteMap[Name]['paramsRaw'];
}
type RouteLocationAsRelativeTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = {
[N in keyof RouteMap]: RouteLocationAsRelativeTyped<RouteMap, N>;
};
interface RouteLocationAsPathTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteQueryAndHash, RouteLocationOptions {
path: LiteralStringUnion<RouteMap[Name]['path']>;
}
type RouteLocationAsPathTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = {
[N in keyof RouteMap]: RouteLocationAsPathTyped<RouteMap, N>;
};
type RouteLocationAsString<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = LiteralStringUnion<RouteMap[keyof RouteMap]['path'], string>;
interface RouteLocationTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap> extends RouteLocation {
name: Extract<Name, RouteRecordName>;
params: RouteMap[Name]['params'];
}
type RouteLocationTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = {
[N in keyof RouteMap]: RouteLocationTyped<RouteMap, N>;
};
interface RouteLocationResolvedTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap> extends RouteLocationTyped<RouteMap, Name> {
href: string;
}
type RouteLocationResolvedTypedList<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> = {
[N in keyof RouteMap]: RouteLocationResolvedTyped<RouteMap, N>;
};
/**
* Type safe versions of types that are exposed by vue-router
*/
/**
* Type safe version of `RouteLocationNormalized`. Accepts the name of the route as a type parameter.
* @see {@link RouteLocationNormalized}
*/
type _RouteLocationNormalized<Name extends _RouteRecordName = _RouteRecordName> = RouteLocationNormalizedTypedList<RouteNamedMap>[Name];
/**
* Type safe version of `RouteLocationNormalizedLoaded`. Accepts the name of the route as a type parameter.
* @see {@link RouteLocationNormalizedLoaded}
*/
type _RouteLocationNormalizedLoaded<Name extends _RouteRecordName = _RouteRecordName> = RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[Name];
/**
* Type safe version of `RouteLocationAsRelative`. Accepts the name of the route as a type parameter.
* @see {@link RouteLocationAsRelative}
*/
type _RouteLocationAsRelativePath<Name extends _RouteRecordName = _RouteRecordName> = RouteLocationAsRelativeTypedList<RouteNamedMap>[Name];
/**
* Type safe version of `RouteLocationResolved` (the returned route of `router.resolve()`).
* Allows passing the name of the route to be passed as a generic.
* @see {@link Router['resolve']}
*/
type _RouteLocationResolved<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationResolvedTypedList<RouteNamedMap>[Name];
/**
* Type safe version of `RouteLocation` . Allows passing the name of the route to be passed as a generic.
* @see {@link RouteLocation}
*/
type _RouteLocation<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationTypedList<RouteNamedMap>[Name];
/**
* Type safe version of `RouteLocationRaw` . Allows passing the name of the route to be passed as a generic.
* @see {@link RouteLocationRaw}
*/
type _RouteLocationRaw<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationAsString<RouteNamedMap> | RouteLocationAsRelativeTypedList<RouteNamedMap>[Name] | RouteLocationAsPathTypedList<RouteNamedMap>[Name];
/**
* Generate a type safe params for a route location. Requires the name of the route to be passed as a generic.
* @see {@link RouteParams}
*/
type _RouteParams<Name extends keyof RouteNamedMap> = RouteNamedMap[Name]['params'];
/**
* Generate a type safe raw params for a route location. Requires the name of the route to be passed as a generic.
* @see {@link RouteParamsRaw}
*/
type _RouteParamsRaw<Name extends keyof RouteNamedMap> = RouteNamedMap[Name]['paramsRaw'];
/**
* Return types for a Navigation Guard. Accepts a type param for the RouteMap.
*/
type NavigationGuardReturnTyped<RouteMap extends _RouteMapGeneric> = void | Error | boolean | RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap];
/**
* Return types for a Navigation Guard. Based on `TypesConfig`
*
* @see {@link TypesConfig}
* @see {@link NavigationGuardReturnTyped}
*/
type NavigationGuardReturn = NavigationGuardReturnTyped<RouteNamedMap>;
/**
* Typed Navigation Guard with a type parameter for `this` and another for the route map.
*/
interface NavigationGuardWithThisTyped<T, RouteMap extends _RouteMapGeneric> {
(this: T, to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], next: NavigationGuardNext): _Awaitable<NavigationGuardReturnTyped<RouteMap>>;
}
/**
* Typed Navigation Guard with a type parameter for `this`. Based on `TypesConfig`
* @see {@link TypesConfig}
* @see {@link NavigationGuardWithThisTyped}
*/
interface NavigationGuardWithThis<T> extends NavigationGuardWithThisTyped<T, RouteNamedMap> {
}
/**
* Typed Navigation Guard. Accepts a type param for the RouteMap.
*/
interface NavigationGuardTyped<RouteMap extends _RouteMapGeneric> {
(to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], next: NavigationGuardNext): _Awaitable<NavigationGuardReturnTyped<RouteMap>>;
}
/**
* Typed Navigation Guard. Based on `TypesConfig`.
* @see {@link TypesConfig}
* @see {@link NavigationGuardWithThisTyped}
*/
interface NavigationGuard extends NavigationGuardTyped<RouteNamedMap> {
}
/**
* Typed Navigation Hook After. Accepts a type param for the RouteMap.
*/
interface NavigationHookAfterTyped<RouteMap extends _RouteMapGeneric> {
(to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], failure?: NavigationFailure | void): unknown;
}
/**
* NOTE: Ideally, these should be moved to vue-router in the future to enable typed routes in the core. What's left to
* confirm is if the strategy relying on a `TypesConfig` is the future proof. Moving this to vue-router would also
* remove the double documentation.
*/
interface _RouterTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> extends Omit<Router, 'resolve' | 'push' | 'replace' | 'beforeEach' | 'beforeResolve' | 'afterEach' | 'currentRoute'> {
/**
* Current {@link RouteLocationNormalized}. Prefer using `useRoute()` instead.
*/
currentRoute: ShallowRef<RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap]>;
/**
* Programmatically navigate to a new URL by pushing an entry in the history
* stack.
*
* @param to - Route location to navigate to
*/
push(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap]): ReturnType<Router['push']>;
/**
* Programmatically navigate to a new URL by replacing the current entry in
* the history stack. Equivalent to `router.push({ replace: true })`.
*
* @param to - Route location to navigate to
*/
replace(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap]): ReturnType<Router['replace']>;
/**
* Returns the {@link RouteLocation | normalized version} of a
* {@link RouteLocationRaw | route location}. Also includes an `href` property
* that includes any existing `base`. By default, the `currentLocation` used is
* `router.currentRoute` and should only be overridden in advanced use cases.
*
* @param to - Raw route location to resolve
* @param currentLocation - Optional current location to resolve against
*/
resolve<Name extends keyof RouteMap = keyof RouteMap>(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPathTyped<RouteMap, Name>, currentLocation?: RouteLocationNormalizedLoaded): RouteLocationResolvedTypedList<RouteMap>[Name];
/**
* Add a navigation guard that executes before any navigation. Returns a
* function that removes the registered guard.
*
* @param guard - navigation guard to add
*/
beforeEach(guard: NavigationGuardWithThisTyped<undefined, RouteMap>): ReturnType<Router['beforeEach']>;
/**
* Add a navigation guard that executes before navigation is about to be
* resolved. At this state all component have been fetched and other
* navigation guards have been successful. Returns a function that removes the
* registered guard.
*
* @param guard - navigation guard to add
* @returns a function that removes the registered guard
*
* @example
* ```js
* router.beforeResolve(to => {
* if (to.meta.requiresAuth && !isAuthenticated) return false
* })
* ```
*
*/
beforeResolve(guard: NavigationGuardWithThisTyped<undefined, RouteMap>): ReturnType<Router['beforeResolve']>;
/**
* Add a navigation hook that is executed after every navigation. Returns a
* function that removes the registered hook.
*
* @param guard - navigation hook to add
* @returns a function that removes the registered hook
*
* @example
* ```js
* router.afterEach((to, from, failure) => {
* if (isNavigationFailure(failure)) {
* console.log('failed navigation', failure)
* }
* })
* ```
*/
afterEach(guard: NavigationHookAfterTyped<RouteMap>): ReturnType<Router['beforeEach']>;
}
/**
* Type safe version of `Router`. Used internally by loaders and other methods to provide a typed API without having to pass the RouteNamedMap.
* @see {@link Router}
*/
type _Router = TypesConfig extends Record<'RouteNamedMap', any> ? _RouterTyped<RouteNamedMap> : Router;
/**
* unplugin-vue-router version of `RouterOptions`.
* @deprecated use `RouterOptions` instead. This type is no longer needed.
* @see {@link RouterOptions}
*/
interface _RouterOptions extends RouterOptions {
/**
* Modify the routes before they are passed to the router. You can modify the existing array or return a
* new one.
* @deprecated `routes` is now required, so you can just modify a copy of the array directly.
*
* @param routes - The routes generated by this plugin and exposed by `vue-router/auto-routes`
*/
extendRoutes?: (routes: RouteRecordRaw[]) => RouteRecordRaw[] | void;
}
/**
* Typed version of `RouterLinkProps`.
*/
interface RouterLinkPropsTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends Omit<RouterLinkProps, 'to'> {
to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[Name] | RouteLocationAsPathTypedList<RouteMap>[Name];
}
/**
* Typed version of `<RouterLink>` component.
*/
interface RouterLinkTyped<RouteMap extends _RouteMapGeneric> {
new (): {
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & RouterLinkPropsTyped<RouteMap>;
$slots: {
default: (arg: UnwrapRef<_UseLinkReturnTyped<RouteMap>>) => VNode[];
};
};
}
/**
* Return type of `useLink()`. Should be exposed by the router instead.
* @internal
*/
interface _UseLinkReturnTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> {
route: ComputedRef<RouteLocationResolvedTypedList<RouteMap>[Name]>;
href: ComputedRef<string>;
isActive: ComputedRef<boolean>;
isExactActive: ComputedRef<boolean>;
navigate(e?: MouseEvent): Promise<void | NavigationFailure>;
}
/**
* Typed version of `useLink()`.
*/
interface UseLinkFnTyped<RouteMap extends _RouteMapGeneric> {
<Name extends keyof RouteMap = keyof RouteMap>(props: {
to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPathTyped<RouteMap, Name> | Ref<RouteLocationRaw>;
replace?: boolean | undefined | Ref<boolean | undefined>;
}): _UseLinkReturnTyped<RouteMap, Name>;
}
/**
* Utility type for raw and non raw params like :id+
*
*/
type ParamValueOneOrMore<isRaw extends boolean> = [
ParamValue<isRaw>,
...ParamValue<isRaw>[]
];
/**
* Utility type for raw and non raw params like :id*
*
*/
type ParamValueZeroOrMore<isRaw extends boolean> = true extends isRaw ? ParamValue<isRaw>[] | undefined | null : ParamValue<isRaw>[] | undefined;
/**
* Utility type for raw and non raw params like :id?
*
*/
type ParamValueZeroOrOne<isRaw extends boolean> = true extends isRaw ? string | number | null | undefined : string;
/**
* Utility type for raw and non raw params like :id
*
*/
type ParamValue<isRaw extends boolean> = true extends isRaw ? string | number : string;
export type { NavigationGuard, NavigationGuardReturn, NavigationGuardTyped, NavigationGuardWithThis, NavigationGuardWithThisTyped, NavigationHookAfterTyped, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, _RouteLocation as RouteLocation, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, _RouteLocationAsRelativePath as RouteLocationAsRelativePath, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, _RouteLocationNormalized as RouteLocationNormalized, _RouteLocationNormalizedLoaded as RouteLocationNormalizedLoaded, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, _RouteLocationRaw as RouteLocationRaw, _RouteLocationResolved as RouteLocationResolved, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteNamedMap, _RouteParams as RouteParams, _RouteParamsRaw as RouteParamsRaw, RouteRecordInfo, _RouteRecordName as RouteRecordName, _Router as Router, RouterLinkPropsTyped, RouterLinkTyped, TypesConfig, UseLinkFnTyped, _RouteMapGeneric, _RouterOptions, _RouterTyped, _UseLinkReturnTyped };
export { E as EditableTreeNode, O as Options, T as TreeNode, b as TreeNodeValueParam, d as TreeNodeValueStatic } from './types-B3fGzmzY.js';
import 'vue-router';
import * as vite from 'vite';
import { O as Options } from './options-EuMjkncO.js';
import { O as Options } from './types-B3fGzmzY.js';
import 'vue-router';

@@ -4,0 +4,0 @@

import {
src_default
} from "./chunk-YHQCGS2V.js";
} from "./chunk-JAQZ7GSU.js";
import "./chunk-HWA3WM2K.js";

@@ -5,0 +5,0 @@ import "./chunk-6F4PWJZI.js";

import * as webpack from 'webpack';
import { O as Options } from './options-EuMjkncO.js';
import { O as Options } from './types-B3fGzmzY.js';
import 'vue-router';

@@ -4,0 +4,0 @@

import {
src_default
} from "./chunk-YHQCGS2V.js";
} from "./chunk-JAQZ7GSU.js";
import "./chunk-HWA3WM2K.js";

@@ -5,0 +5,0 @@ import "./chunk-6F4PWJZI.js";

{
"name": "unplugin-vue-router",
"version": "0.9.1",
"version": "0.10.0",
"type": "module",

@@ -95,2 +95,10 @@ "description": "File based typed routing for Vue Router",

},
"./data-loaders": {
"types": {
"require": "./dist/data-loaders/index.d.cts",
"import": "./dist/data-loaders/index.d.ts"
},
"require": "./dist/data-loaders/index.cjs",
"import": "./dist/data-loaders/index.js"
},
"./data-loaders/basic": {

@@ -145,3 +153,3 @@ "types": {

"dependencies": {
"@babel/types": "^7.24.6",
"@babel/types": "^7.24.7",
"@rollup/pluginutils": "^5.1.0",

@@ -154,10 +162,10 @@ "@vue-macros/common": "^1.10.4",

"local-pkg": "^0.5.0",
"mlly": "^1.7.0",
"mlly": "^1.7.1",
"pathe": "^1.1.2",
"scule": "^1.3.0",
"unplugin": "^1.10.1",
"yaml": "^2.4.3"
"yaml": "^2.4.5"
},
"peerDependencies": {
"vue-router": "^4.3.0"
"vue-router": "^4.4.0"
},

@@ -171,5 +179,5 @@ "peerDependenciesMeta": {

"@pinia/colada": "^0.6.0",
"@shikijs/vitepress-twoslash": "1.6.2",
"@tanstack/vue-query": "^5.40.0",
"@types/node": "^20.14.0",
"@shikijs/vitepress-twoslash": "1.6.5",
"@tanstack/vue-query": "^5.45.0",
"@types/node": "^20.14.2",
"@vitest/coverage-v8": "^1.6.0",

@@ -182,11 +190,11 @@ "@vitest/ui": "^1.6.0",

"enquirer": "^2.4.1",
"execa": "^9.1.0",
"execa": "^9.2.0",
"firebase": "^10.12.2",
"happy-dom": "^14.12.0",
"lint-staged": "^15.2.5",
"lint-staged": "^15.2.7",
"minimist": "^1.2.8",
"nodemon": "^3.1.2",
"nodemon": "^3.1.3",
"p-series": "^3.0.0",
"pinia": "^2.1.7",
"prettier": "^3.3.0",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",

@@ -200,13 +208,13 @@ "rollup": "^4.18.0",

"unplugin-vue-markdown": "^0.26.2",
"vite": "^5.2.12",
"vitepress": "1.2.2",
"vite": "^5.3.1",
"vitepress": "1.2.3",
"vitest": "^1.6.0",
"vue": "^3.4.27",
"vue-router": "4.3.2",
"vue": "^3.4.29",
"vue-router": "^4.4.0",
"vue-router-mock": "^1.1.0",
"vue-tsc": "^2.0.19",
"vue-tsc": "^2.0.21",
"vuefire": "^3.1.23",
"webpack": "^5.91.0",
"webpack": "^5.92.0",
"yorkie": "^2.0.0",
"unplugin-vue-router": "0.9.1"
"unplugin-vue-router": "0.10.0"
},

@@ -213,0 +221,0 @@ "scripts": {

@@ -15,3 +15,3 @@ # unplugin-vue-router

This build-time plugin simplifies your routing setup **and** makes it safer and easier to use thanks to TypeScript. Requires Vue Router at least 4.1.0.
This build-time plugin simplifies your routing setup **and** makes it safer and easier to use thanks to TypeScript. Requires Vue Router >=4.4.0.

@@ -158,7 +158,6 @@ ⚠️ This package is still experimental. If you found any issue, design flaw, or have ideas to improve it, please, open an [issue](https://github.com/posva/unplugin-vue-router/issues/new/choose) or a [Discussion](https://github.com/posva/unplugin-vue-router/discussions).

Finally, you should replace your imports from `vue-router` to `vue-router/auto`:
Finally, import the generated routes from `vue-router/auto-routes` and pass them to the router:
```diff
-import { createRouter, createWebHistory } from 'vue-router'
+import { createRouter, createWebHistory } from 'vue-router/auto'
import { createRouter, createWebHistory } from 'vue-router'
+import { routes } from 'vue-router/auto-routes'

@@ -165,0 +164,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc