editLink |
---|
API Documentation
- HistoryState
- LocationAsRelativeRaw
- MatcherLocation
- MatcherLocationAsPath
- NavigationFailure
- NavigationGuard
- NavigationGuardNext
- NavigationGuardWithThis
- NavigationHookAfter
- NavigationRedirectError
- RouteLocationAsPathGeneric
- RouteLocationAsPathTyped
- RouteLocationAsRelativeGeneric
- RouteLocationAsRelativeTyped
- RouteLocationGeneric
- RouteLocationMatched
- RouteLocationNamedRaw
- RouteLocationNormalizedGeneric
- RouteLocationNormalizedLoadedGeneric
- RouteLocationNormalizedLoadedTyped
- RouteLocationNormalizedTyped
- RouteLocationOptions
- RouteLocationPathRaw
- RouteLocationResolvedGeneric
- RouteLocationResolvedTyped
- RouteLocationTyped
- RouteMeta
- RouteQueryAndHash
- RouteRecordInfo
- RouteRecordMultipleViews
- RouteRecordMultipleViewsWithChildren
- RouteRecordNormalized
- RouteRecordRedirect
- RouteRecordSingleView
- RouteRecordSingleViewWithChildren
- Router
- RouterHistory
- RouterLinkProps
- RouterMatcher
- RouterOptions
- RouterScrollBehavior
- RouterViewProps
- TypesConfig
- UseLinkOptions
- UseLinkReturn
- _PathParserOptions
- _RouteLocationBase
- _RouteRecordBase
- _RouterLinkI
Ƭ LocationQuery: Record
<string
, LocationQueryValue
| LocationQueryValue
[]>
Normalized query object that appears in RouteLocationNormalized
Ƭ LocationQueryRaw: Record
<string
| number
, LocationQueryValueRaw
| LocationQueryValueRaw
[]>
Loose LocationQuery object that can be passed to functions like Router.push and Router.replace or anywhere when creating a RouteLocationRaw
Ƭ LocationQueryValue: string
| null
Possible values in normalized LocationQuery. null
renders the query
param but without an =
.
Example
?isNull&isEmpty=&other=other
gives
`{ isNull: null, isEmpty: '', other: 'other' }`.
Ƭ LocationQueryValueRaw: LocationQueryValue
| number
| undefined
Possible values when defining a query.
Ƭ NavigationGuardNextCallback: (vm
: ComponentPublicInstance
) => unknown
Callback that can be passed to next()
in beforeRouteEnter()
guards.
▸ (vm
): unknown
Name | Type |
---|---|
vm |
ComponentPublicInstance |
unknown
Ƭ NavigationGuardReturn: void
| Error
| boolean
| RouteLocationRaw
Return types for a Navigation Guard. Based on TypesConfig
See
Ƭ ParamValue<isRaw
>: true
extends isRaw
? string
| number
: string
Utility type for raw and non raw params like :id
Name | Type |
---|---|
isRaw |
extends boolean |
Ƭ ParamValueOneOrMore<isRaw
>: [ParamValue
<isRaw
>, ...ParamValue<isRaw>[]]
Utility type for raw and non raw params like :id+
Name | Type |
---|---|
isRaw |
extends boolean |
Ƭ ParamValueZeroOrMore<isRaw
>: true
extends isRaw
? ParamValue
<isRaw
>[] | undefined
| null
: ParamValue
<isRaw
>[] | undefined
Utility type for raw and non raw params like :id*
Name | Type |
---|---|
isRaw |
extends boolean |
Ƭ ParamValueZeroOrOne<isRaw
>: true
extends isRaw
? string
| number
| null
| undefined
: string
Utility type for raw and non raw params like :id?
Name | Type |
---|---|
isRaw |
extends boolean |
Ƭ PathParserOptions: Pick
<_PathParserOptions
, "end"
| "sensitive"
| "strict"
>
Ƭ RouteComponent: Component
| DefineComponent
Allowed Component in RouteLocationMatched
Ƭ RouteLocation<Name
>: RouteMapGeneric
extends RouteMap
? RouteLocationGeneric
: RouteLocationTypedList
<RouteMap
>[Name
]
RouteLocationRaw resolved using the matcher
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationAsPath<Name
>: RouteMapGeneric
extends RouteMap
? RouteLocationAsPathGeneric
: RouteLocationAsPathTypedList
<RouteMap
>[Name
]
Route location as an object with a path
property.
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationAsPathTypedList<RouteMap
>: { [N in keyof RouteMap]: RouteLocationAsPathTyped<RouteMap, N> }
List of all possible RouteLocationAsPath indexed by the route name.
Name | Type |
---|---|
RouteMap |
extends RouteMapGeneric = RouteMapGeneric |
Ƭ RouteLocationAsRelative<Name
>: RouteMapGeneric
extends RouteMap
? RouteLocationAsRelativeGeneric
: RouteLocationAsRelativeTypedList
<RouteMap
>[Name
]
Route location relative to the current location. It accepts other properties than path
like params
, query
and
hash
to conveniently change them.
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationAsRelativeTypedList<RouteMap
>: { [N in keyof RouteMap]: RouteLocationAsRelativeTyped<RouteMap, N> }
List of all possible RouteLocationAsRelative indexed by the route name.
Name | Type |
---|---|
RouteMap |
extends RouteMapGeneric = RouteMapGeneric |
Ƭ RouteLocationAsString<Name
>: RouteMapGeneric
extends RouteMap
? string
: _LiteralUnion
<RouteLocationAsStringTypedList
<RouteMap
>[Name
], string
>
Same as RouteLocationAsPath but as a string literal.
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationAsStringTyped<RouteMap
, Name
>: RouteMap
[Name
]["path"
]
Helper to generate a type safe version of the RouteLocationAsString type.
Name | Type |
---|---|
RouteMap |
extends RouteMapGeneric = RouteMapGeneric |
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationAsStringTypedList<RouteMap
>: { [N in keyof RouteMap]: RouteLocationAsStringTyped<RouteMap, N> }
List of all possible RouteLocationAsString indexed by the route name.
Name | Type |
---|---|
RouteMap |
extends RouteMapGeneric = RouteMapGeneric |
Ƭ RouteLocationNormalized<Name
>: RouteMapGeneric
extends RouteMap
? RouteLocationNormalizedGeneric
: RouteLocationNormalizedTypedList
<RouteMap
>[Name
]
Similar to RouteLocation but its
matched
property cannot contain redirect records
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationNormalizedLoaded<Name
>: RouteMapGeneric
extends RouteMap
? RouteLocationNormalizedLoadedGeneric
: RouteLocationNormalizedLoadedTypedList
<RouteMap
>[Name
]
Similar to RouteLocationNormalized but its components
do not contain any function to lazy load components.
In other words, it's ready to be rendered by <RouterView>
.
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationNormalizedLoadedTypedList<RouteMap
>: { [N in keyof RouteMap]: RouteLocationNormalizedLoadedTyped<RouteMap, N> }
List of all possible RouteLocationNormalizedLoaded indexed by the route name.
Name | Type |
---|---|
RouteMap |
extends RouteMapGeneric = RouteMapGeneric |
Ƭ RouteLocationNormalizedTypedList<RouteMap
>: { [N in keyof RouteMap]: RouteLocationNormalizedTyped<RouteMap, N> }
List of all possible RouteLocationNormalized indexed by the route name.
Name | Type |
---|---|
RouteMap |
extends RouteMapGeneric = RouteMapGeneric |
Ƭ RouteLocationRaw<Name
>: RouteMapGeneric
extends RouteMap
? RouteLocationAsString
| RouteLocationAsRelativeGeneric
| RouteLocationAsPathGeneric
: _LiteralUnion
<RouteLocationAsStringTypedList
<RouteMap
>[Name
], string
> | RouteLocationAsRelativeTypedList
<RouteMap
>[Name
] | RouteLocationAsPathTypedList
<RouteMap
>[Name
]
Route location that can be passed to router.push()
and other user-facing APIs.
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationResolved<Name
>: RouteMapGeneric
extends RouteMap
? RouteLocationResolvedGeneric
: RouteLocationResolvedTypedList
<RouteMap
>[Name
]
Route location resolved with router.resolve()
.
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteLocationResolvedTypedList<RouteMap
>: { [N in keyof RouteMap]: RouteLocationResolvedTyped<RouteMap, N> }
List of all possible RouteLocationResolved indexed by the route name.
Name | Type |
---|---|
RouteMap |
extends RouteMapGeneric = RouteMapGeneric |
Ƭ RouteLocationTypedList<RouteMap
>: { [N in keyof RouteMap]: RouteLocationTyped<RouteMap, N> }
List of all possible RouteLocation indexed by the route name.
Name | Type |
---|---|
RouteMap |
extends RouteMapGeneric = RouteMapGeneric |
Ƭ RouteMap: TypesConfig
extends Record
<"RouteNamedMap"
, infer RouteNamedMap> ? RouteNamedMap
: RouteMapGeneric
Convenience type to get the typed RouteMap or a generic one if not provided. It is extracted from the TypesConfig if it exists, it becomes RouteMapGeneric otherwise.
Ƭ RouteMapGeneric: Record
<string
| symbol
, RouteRecordInfo
>
Generic version of the RouteMap
.
Ƭ RouteParamValue: string
Ƭ RouteParamValueRaw: RouteParamValue
| number
| null
| undefined
Ƭ RouteParams<Name
>: RouteMap
[Name
]["params"
]
Generate a type safe params for a route location. Requires the name of the route to be passed as a generic.
See
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteParamsGeneric: Record
<string
, RouteParamValue
| RouteParamValue
[]>
Ƭ RouteParamsRaw<Name
>: RouteMap
[Name
]["paramsRaw"
]
Generate a type safe raw params for a route location. Requires the name of the route to be passed as a generic.
See
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
Ƭ RouteParamsRawGeneric: Record
<string
, RouteParamValueRaw
| Exclude
<RouteParamValueRaw
, null
| undefined
>[]>
Ƭ RouteRecord: RouteRecordNormalized
Normalized version of a route record.
Ƭ RouteRecordName: RouteMapGeneric
extends RouteMap
? RouteRecordNameGeneric
: keyof RouteMap
Possible values for a route record after normalization
NOTE: since RouteRecordName
is a type, it evaluates too early and it's often the generic version RouteRecordNameGeneric. If you need a typed version of all of the names of routes, use keyof RouteMap
Ƭ RouteRecordNameGeneric: string
| symbol
| undefined
Generic version of RouteRecordName.
Ƭ RouteRecordRaw: RouteRecordSingleView
| RouteRecordSingleViewWithChildren
| RouteRecordMultipleViews
| RouteRecordMultipleViewsWithChildren
| RouteRecordRedirect
Ƭ RouteRecordRedirectOption: RouteLocationRaw
| (to
: RouteLocation
) => RouteLocationRaw
Ƭ _Awaitable<T
>: T
| PromiseLike
<T
>
Maybe a promise maybe not
Name |
---|
T |
Ƭ _RouteRecordProps<Name
>: boolean
| Record
<string
, any
> | (to
: RouteLocationNormalized
<Name
>) => Record
<string
, any
>
Name | Type |
---|---|
Name |
extends keyof RouteMap = keyof RouteMap |
• Const
RouterLink: _RouterLinkI
Component to render a link that triggers a navigation on click.
• Const
RouterView: () => { $props
: AllowedComponentProps
& ComponentCustomProps
& VNodeProps
& RouterViewProps
; $slots
: { default?
: (__namedParameters
: { Component
: VNode
<RendererNode
, RendererElement
, { [key: string]
: any
; }> ; route
: RouteLocationNormalizedLoadedGeneric
}) => VNode
<RendererNode
, RendererElement
, { [key: string]
: any
; }>[] } }
Component to display the current route the user is at.
• new RouterView(): Object
Component to display the current route the user is at.
Object
Name | Type |
---|---|
$props |
AllowedComponentProps & ComponentCustomProps & VNodeProps & RouterViewProps |
$slots |
{ default? : (__namedParameters : { Component : VNode <RendererNode , RendererElement , { [key: string] : any ; }> ; route : RouteLocationNormalizedLoadedGeneric }) => VNode <RendererNode , RendererElement , { [key: string] : any ; }>[] } |
$slots.default? |
(__namedParameters : { Component : VNode <RendererNode , RendererElement , { [key: string] : any ; }> ; route : RouteLocationNormalizedLoadedGeneric }) => VNode <RendererNode , RendererElement , { [key: string] : any ; }>[] |
• Const
START_LOCATION: RouteLocationNormalizedLoaded
Initial route location where the router is. Can be used in navigation guards to differentiate the initial navigation.
Example
import { START_LOCATION } from 'vue-router'
router.beforeEach((to, from) => {
if (from === START_LOCATION) {
// initial navigation
}
})
• Const
matchedRouteKey: InjectionKey
<ComputedRef
<undefined
| RouteRecordNormalized
>>
RouteRecord being rendered by the closest ancestor Router View. Used for
onBeforeRouteUpdate
and onBeforeRouteLeave
. rvlm stands for Router View
Location Matched
• Const
routeLocationKey: InjectionKey
<RouteLocationNormalizedLoadedGeneric
>
Allows overriding the current route returned by useRoute
in tests. rl
stands for route location
• Const
routerKey: InjectionKey
<Router
>
Allows overriding the router instance returned by useRouter
in tests. r
stands for router
• Const
routerViewLocationKey: InjectionKey
<Ref
<RouteLocationNormalizedLoadedGeneric
>>
Allows overriding the current route used by router-view. Internally this is
used when the route
prop is passed.
• Const
viewDepthKey: InjectionKey
<number
| Ref
<number
>>
Allows overriding the router view depth to control which component in
matched
is rendered. rvd stands for Router View Depth
▸ createMemoryHistory(base?
): RouterHistory
Creates an in-memory based history. The main purpose of this history is to handle SSR. It starts in a special location that is nowhere.
It's up to the user to replace that location with the starter location by either calling router.push
or router.replace
.
Name | Type | Default value | Description |
---|---|---|---|
base |
string |
'' |
Base applied to all urls, defaults to '/' |
a history object that can be passed to the router constructor
▸ createRouter(options
): Router
Creates a Router instance that can be used by a Vue app.
Name | Type | Description |
---|---|---|
options |
RouterOptions |
RouterOptions |
▸ createRouterMatcher(routes
, globalOptions
): RouterMatcher
Creates a Router Matcher.
Name | Type | Description |
---|---|---|
routes |
readonly RouteRecordRaw [] |
array of initial routes |
globalOptions |
PathParserOptions |
global route options |
▸ createWebHashHistory(base?
): RouterHistory
Creates a hash history. Useful for web applications with no host (e.g. file://
) or when configuring a server to
handle any URL is not possible.
Name | Type | Description |
---|---|---|
base? |
string |
optional base to provide. Defaults to location.pathname + location.search If there is a <base> tag in the head , its value will be ignored in favor of this parameter but note it affects all the history.pushState() calls, meaning that if you use a <base> tag, it's href value has to match this parameter (ignoring anything after the # ). |
Example
// at https://example.com/folder
createWebHashHistory() // gives a url of `https://example.com/folder#`
createWebHashHistory('/folder/') // gives a url of `https://example.com/folder/#`
// if the `#` is provided in the base, it won't be added by `createWebHashHistory`
createWebHashHistory('/folder/#/app/') // gives a url of `https://example.com/folder/#/app/`
// you should avoid doing this because it changes the original url and breaks copying urls
createWebHashHistory('/other-folder/') // gives a url of `https://example.com/other-folder/#`
// at file:///usr/etc/folder/index.html
// for locations with no `host`, the base is ignored
createWebHashHistory('/iAmIgnored') // gives a url of `file:///usr/etc/folder/index.html#`
▸ createWebHistory(base?
): RouterHistory
Creates an HTML5 history. Most common history for single page applications.
Name | Type |
---|---|
base? |
string |
▸ isNavigationFailure(error
, type?
): error is NavigationRedirectError
Check if an object is a NavigationFailure.
Name | Type | Description |
---|---|---|
error |
any |
possible NavigationFailure |
type? |
NAVIGATION_GUARD_REDIRECT |
optional types to check for |
error is NavigationRedirectError
Example
import { isNavigationFailure, NavigationFailureType } from 'vue-router'
router.afterEach((to, from, failure) => {
// Any kind of navigation failure
if (isNavigationFailure(failure)) {
// ...
}
// Only duplicated navigations
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
// ...
}
// Aborted or canceled navigations
if (isNavigationFailure(failure, NavigationFailureType.aborted | NavigationFailureType.canceled)) {
// ...
}
})
▸ isNavigationFailure(error
, type?
): error is NavigationFailure
Name | Type |
---|---|
error |
any |
type? |
ErrorTypes | NavigationFailureType |
error is NavigationFailure
▸ loadRouteLocation(route
): Promise
<RouteLocationNormalizedLoaded
>
Ensures a route is loaded, so it can be passed as o prop to <RouterView>
.
Name | Type | Description |
---|---|---|
route |
RouteLocationNormalizedGeneric | RouteLocationGeneric |
resolved route to load |
Promise
<RouteLocationNormalizedLoaded
>
▸ onBeforeRouteLeave(leaveGuard
): void
Add a navigation guard that triggers whenever the component for the current location is about to be left. Similar to beforeRouteLeave but can be used in any component. The guard is removed when the component is unmounted.
Name | Type | Description |
---|---|---|
leaveGuard |
NavigationGuard |
NavigationGuard |
void
▸ onBeforeRouteUpdate(updateGuard
): void
Add a navigation guard that triggers whenever the current location is about to be updated. Similar to beforeRouteUpdate but can be used in any component. The guard is removed when the component is unmounted.
Name | Type | Description |
---|---|---|
updateGuard |
NavigationGuard |
NavigationGuard |
void
▸ parseQuery(search
): LocationQuery
Transforms a queryString into a LocationQuery object. Accept both, a
version with the leading ?
and without Should work as URLSearchParams
Name | Type | Description |
---|---|---|
search |
string |
search string to parse |
a query object
▸ stringifyQuery(query
): string
Stringifies a LocationQueryRaw object. Like URLSearchParams
, it
doesn't prepend a ?
Name | Type | Description |
---|---|---|
query |
LocationQueryRaw |
query object to stringify |
string
string version of the query without the leading ?
▸ useLink<Name
>(props
): UseLinkReturn
<Name
>
Returns the internal behavior of a RouterLink without the rendering part.
Name | Type |
---|---|
Name |
extends string | symbol = string | symbol |
Name | Type | Description |
---|---|---|
props |
UseLinkOptions <Name > |
a to location and an optional replace flag |
UseLinkReturn
<Name
>
▸ useRoute<Name
>(_name?
): RouteLocationNormalizedLoaded
<Name
>
Returns the current route location. Equivalent to using $route
inside
templates.
Name | Type |
---|---|
Name |
extends string | symbol = string | symbol |
Name | Type |
---|---|
_name? |
Name |
RouteLocationNormalizedLoaded
<Name
>
▸ useRouter(): Router
Returns the router instance. Equivalent to using $router
inside
templates.