"lint-staged": "^15.2.10",
"minimist": "^1.2.8",
"p-series": "^3.0.0",
- "prettier": "^2.8.8",
+ "prettier": "^3.5.2",
"semver": "^7.6.3",
"simple-git-hooks": "^2.11.1",
"typedoc": "^0.26.11",
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
normalized: RouteLocationResolved
toResolve?: MatcherLocationRaw & Required<RouteQueryAndHash>
}
- >
+ >,
>(locs: T) {
return locs
}
describe('beforeRouteLeave', () => {
it('invokes with the component context', async () => {
expect.assertions(2)
- const spy = vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- })
+ const spy = vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ })
const WithLeave = defineComponent({
template: `text`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
template: `text`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
data: () => ({ counter: 0 }),
- beforeRouteLeave: vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- }),
+ beforeRouteLeave: vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ }),
})
const WithLeaveTwo = defineComponent({
template: `text`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
data: () => ({ counter: 0 }),
- beforeRouteLeave: vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- }),
+ beforeRouteLeave: vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ }),
})
const router = createRouter({
template: `<router-view/>`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
data: () => ({ counter: 0 }),
- beforeRouteLeave: vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- }),
+ beforeRouteLeave: vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ }),
})
const WithLeave = defineComponent({
template: `text`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
data: () => ({ counter: 0 }),
- beforeRouteLeave: vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- }),
+ beforeRouteLeave: vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ }),
})
const router = createRouter({
`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
data: () => ({ counter: 0 }),
- beforeRouteLeave: vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- }),
+ beforeRouteLeave: vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ }),
})
const WithLeaveOne = defineComponent({
template: `text`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
data: () => ({ counter: 0 }),
- beforeRouteLeave: vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- }),
+ beforeRouteLeave: vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ }),
})
const WithLeaveTwo = defineComponent({
template: `text`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
data: () => ({ counter: 0 }),
- beforeRouteLeave: vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- }),
+ beforeRouteLeave: vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ }),
})
const router = createRouter({
describe('beforeRouteUpdate', () => {
it('invokes with the component context', async () => {
expect.assertions(2)
- const spy = vi
- .fn()
- .mockImplementationOnce(function (this: any, to, from, next) {
- expect(typeof this.counter).toBe('number')
- next()
- })
+ const spy = vi.fn().mockImplementationOnce(function (
+ this: any,
+ to,
+ from,
+ next
+ ) {
+ expect(typeof this.counter).toBe('number')
+ next()
+ })
const WithParam = defineComponent({
template: `text`,
// we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
const [promise, resolve, reject] = fakePromise()
return {
- component: vi.fn(() => promise.then(() => ({} as RouteComponent))),
+ component: vi.fn(() => promise.then(() => ({}) as RouteComponent)),
promise,
resolve,
reject,
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
propClass != null
? propClass
: globalClass != null
- ? globalClass
- : defaultClass
+ ? globalClass
+ : defaultClass
? routePropsOption === true
? route.params
: typeof routePropsOption === 'function'
- ? routePropsOption(route)
- : routePropsOption
+ ? routePropsOption(route)
+ : routePropsOption
: null
const onVnodeUnmounted: VNodeProps['onVnodeUnmounted'] = vnode => {
return isArray(a)
? isEquivalentArray(a, b)
: isArray(b)
- ? isEquivalentArray(b, a)
- : a === b
+ ? isEquivalentArray(b, a)
+ : a === b
}
/**
record =>
record.components &&
Promise.all(
- Object.keys(record.components).reduce((promises, name) => {
- const rawComponent = record.components![name]
- if (
- typeof rawComponent === 'function' &&
- !('displayName' in rawComponent)
- ) {
- promises.push(
- (rawComponent as Lazy<RouteComponent>)().then(resolved => {
- if (!resolved)
- return Promise.reject(
- new Error(
- `Couldn't resolve component "${name}" at "${record.path}". Ensure you passed a function that returns a promise.`
- )
- )
+ Object.keys(record.components).reduce(
+ (promises, name) => {
+ const rawComponent = record.components![name]
+ if (
+ typeof rawComponent === 'function' &&
+ !('displayName' in rawComponent)
+ ) {
+ promises.push(
+ (rawComponent as Lazy<RouteComponent>)().then(
+ resolved => {
+ if (!resolved)
+ return Promise.reject(
+ new Error(
+ `Couldn't resolve component "${name}" at "${record.path}". Ensure you passed a function that returns a promise.`
+ )
+ )
- const resolvedComponent = isESModule(resolved)
- ? resolved.default
- : resolved
- // keep the resolved module for plugins like data loaders
- record.mods[name] = resolved
- // replace the function with the resolved component
- // cannot be null or undefined because we went into the for loop
- record.components![name] = resolvedComponent
- return
- })
- )
- }
- return promises
- }, [] as Array<Promise<RouteComponent | null | undefined>>)
+ const resolvedComponent = isESModule(resolved)
+ ? resolved.default
+ : resolved
+ // keep the resolved module for plugins like data loaders
+ record.mods[name] = resolved
+ // replace the function with the resolved component
+ // cannot be null or undefined because we went into the for loop
+ record.components![name] = resolvedComponent
+ return
+ }
+ )
+ )
+ }
+ return promises
+ },
+ [] as Array<Promise<RouteComponent | null | undefined>>
+ )
)
)
).then(() => route as RouteLocationNormalizedLoaded)
normalizedQuery[key] = isArray(value)
? value.map(v => (v == null ? null : '' + v))
: value == null
- ? value
- : '' + value
+ ? value
+ : '' + value
}
}
*/
export type ParamValueOneOrMore<isRaw extends boolean> = [
ParamValue<isRaw>,
- ...ParamValue<isRaw>[]
+ ...ParamValue<isRaw>[],
]
/**
*/
export interface RouteLocationTyped<
RouteMap extends RouteMapGeneric,
- Name extends keyof RouteMap
+ Name extends keyof RouteMap,
> extends RouteLocationGeneric {
// Extract is needed because keyof can produce numbers
name: Extract<Name, string | symbol>
* @internal
*/
export type RouteLocationTypedList<
- RouteMap extends RouteMapGeneric = RouteMapGeneric
+ RouteMap extends RouteMapGeneric = RouteMapGeneric,
> = { [N in keyof RouteMap]: RouteLocationTyped<RouteMap, N> }
/**
*/
export interface RouteLocationNormalizedTyped<
RouteMap extends RouteMapGeneric = RouteMapGeneric,
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> extends RouteLocationNormalizedGeneric {
name: Extract<Name, string | symbol>
// we don't override path because it could contain params and in practice it's just not useful
* @internal
*/
export type RouteLocationNormalizedTypedList<
- RouteMap extends RouteMapGeneric = RouteMapGeneric
+ RouteMap extends RouteMapGeneric = RouteMapGeneric,
> = { [N in keyof RouteMap]: RouteLocationNormalizedTyped<RouteMap, N> }
/**
*/
export interface RouteLocationNormalizedLoadedTyped<
RouteMap extends RouteMapGeneric = RouteMapGeneric,
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> extends RouteLocationNormalizedLoadedGeneric {
name: Extract<Name, string | symbol>
// we don't override path because it could contain params and in practice it's just not useful
* @internal
*/
export type RouteLocationNormalizedLoadedTypedList<
- RouteMap extends RouteMapGeneric = RouteMapGeneric
+ RouteMap extends RouteMapGeneric = RouteMapGeneric,
> = { [N in keyof RouteMap]: RouteLocationNormalizedLoadedTyped<RouteMap, N> }
/**
*/
export interface RouteLocationAsRelativeTyped<
RouteMap extends RouteMapGeneric = RouteMapGeneric,
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> extends RouteLocationAsRelativeGeneric {
name?: Extract<Name, string | symbol>
params?: RouteMap[Name]['paramsRaw']
* @internal
*/
export type RouteLocationAsRelativeTypedList<
- RouteMap extends RouteMapGeneric = RouteMapGeneric
+ RouteMap extends RouteMapGeneric = RouteMapGeneric,
> = { [N in keyof RouteMap]: RouteLocationAsRelativeTyped<RouteMap, N> }
/**
*/
export interface RouteLocationAsPathTyped<
RouteMap extends RouteMapGeneric = RouteMapGeneric,
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> extends RouteLocationAsPathGeneric {
path: _LiteralUnion<RouteMap[Name]['path']>
* @internal
*/
export type RouteLocationAsPathTypedList<
- RouteMap extends RouteMapGeneric = RouteMapGeneric
+ RouteMap extends RouteMapGeneric = RouteMapGeneric,
> = { [N in keyof RouteMap]: RouteLocationAsPathTyped<RouteMap, N> }
/**
*/
export type RouteLocationAsStringTyped<
RouteMap extends RouteMapGeneric = RouteMapGeneric,
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> = RouteMap[Name]['path']
/**
* @internal
*/
export type RouteLocationAsStringTypedList<
- RouteMap extends RouteMapGeneric = RouteMapGeneric
+ RouteMap extends RouteMapGeneric = RouteMapGeneric,
> = { [N in keyof RouteMap]: RouteLocationAsStringTyped<RouteMap, N> }
/**
*/
export interface RouteLocationResolvedTyped<
RouteMap extends RouteMapGeneric,
- Name extends keyof RouteMap
+ Name extends keyof RouteMap,
> extends RouteLocationTyped<RouteMap, Name> {
/**
* Resolved `href` for the route location that will be set on the `<a href="...">`.
* @internal
*/
export type RouteLocationResolvedTypedList<
- RouteMap extends RouteMapGeneric = RouteMapGeneric
+ RouteMap extends RouteMapGeneric = RouteMapGeneric,
> = { [N in keyof RouteMap]: RouteLocationResolvedTyped<RouteMap, N> }
/**
* {@link RouteLocationNormalizedTyped.matched | `matched` property} cannot contain redirect records
*/
export type RouteLocationNormalized<
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> = RouteMapGeneric extends RouteMap
? RouteLocationNormalizedGeneric
: RouteLocationNormalizedTypedList<RouteMap>[Name]
* In other words, it's ready to be rendered by `<RouterView>`.
*/
export type RouteLocationNormalizedLoaded<
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> = RouteMapGeneric extends RouteMap
? RouteLocationNormalizedLoadedGeneric
: RouteLocationNormalizedLoadedTypedList<RouteMap>[Name]
* `hash` to conveniently change them.
*/
export type RouteLocationAsRelative<
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> = RouteMapGeneric extends RouteMap
? RouteLocationAsRelativeGeneric
: RouteLocationAsRelativeTypedList<RouteMap>[Name]
* Route location resolved with {@link Router | `router.resolve()`}.
*/
export type RouteLocationResolved<
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> = RouteMapGeneric extends RouteMap
? RouteLocationResolvedGeneric
: RouteLocationResolvedTypedList<RouteMap>[Name]
* Same as {@link RouteLocationAsPath} but as a string literal.
*/
export type RouteLocationAsString<
- Name extends keyof RouteMap = keyof RouteMap
+ Name extends keyof RouteMap = keyof RouteMap,
> = RouteMapGeneric extends RouteMap
? string
: _LiteralUnion<RouteLocationAsStringTypedList<RouteMap>[Name], string>
// TODO: could probably be inferred from the Params
ParamsRaw extends RouteParamsRawGeneric = RouteParamsRawGeneric,
Params extends RouteParamsGeneric = RouteParamsGeneric,
- Meta extends RouteMeta = RouteMeta
+ Meta extends RouteMeta = RouteMeta,
> {
name: Name
path: Path
/**
* Convenience type to get the typed RouteMap or a generic one if not provided. It is extracted from the {@link TypesConfig} if it exists, it becomes {@link RouteMapGeneric} otherwise.
*/
-export type RouteMap = TypesConfig extends Record<
- 'RouteNamedMap',
- infer RouteNamedMap
->
- ? RouteNamedMap
- : RouteMapGeneric
+export type RouteMap =
+ TypesConfig extends Record<'RouteNamedMap', infer RouteNamedMap>
+ ? RouteNamedMap
+ : RouteMapGeneric
/**
* Generic version of the `RouteMap`.
specifier: ^3.0.0
version: 3.0.0
prettier:
- specifier: ^2.8.8
- version: 2.8.8
+ specifier: ^3.5.2
+ version: 3.5.2
semver:
specifier: ^7.6.3
version: 7.6.3
preact@10.25.0:
resolution: {integrity: sha512-6bYnzlLxXV3OSpUxLdaxBmE7PMOu0aR3pG6lryK/0jmvcDFPlcXGQAt5DpK3RITWiDrfYZRI0druyaK/S9kYLg==}
- prettier@2.8.8:
- resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==}
- engines: {node: '>=10.13.0'}
+ prettier@3.5.2:
+ resolution: {integrity: sha512-lc6npv5PH7hVqozBR7lkBNOGXV9vMwROAPlumdBkX0wTbbzPu/U1hk5yL8p2pt4Xoc+2mkT8t/sow2YrV/M5qg==}
+ engines: {node: '>=14'}
hasBin: true
pretty-ms@9.1.0:
preact@10.25.0: {}
- prettier@2.8.8: {}
+ prettier@3.5.2: {}
pretty-ms@9.1.0:
dependencies: