From: Eduardo San Martin Morote Date: Tue, 8 Sep 2020 16:25:20 +0000 (+0200) Subject: docs(api): types X-Git-Tag: v4.0.0-beta.10~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16926b48febda8a5e25e1223cdf8395608239a80;p=thirdparty%2Fvuejs%2Frouter.git docs(api): types --- diff --git a/docs/api/index.md b/docs/api/index.md index 5a792ea7..531270ff 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -359,6 +359,28 @@ export declare enum NavigationFailureType | cancelled | 8 | A cancelled navigation is a navigation that failed because a more recent navigation finished started (not necessarily finished). | | duplicated | 16 | A duplicated navigation is a navigation that failed because it was initiated while already being at the exact same location. | +## START_LOCATION + +Initial route location where the router is. Can be used in navigation guards to differentiate the initial navigation. + +**Signature:** + +```typescript +START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded +``` + +### Examples + +```js +import { START_LOCATION } from 'vue-router' + +router.beforeEach((to, from) => { + if (from === START_LOCATION) { + // initial navigation + } +}) +``` + ## Composition API ### onBeforeRouteLeave @@ -408,3 +430,35 @@ TODO: ## TypeScript Here are some of the interfaces and types used by Vue Router. The documentation references them to give you an idea of the existing properties in objects. + +## NavigationGuard + +Navigation guard. See [Navigation Guards](/guide/advanced/navigation-guards.md). + +**Signature:** + +```typescript +export interface NavigationGuard { + ( + to: RouteLocationNormalized, + from: RouteLocationNormalized, + next: NavigationGuardNext + ): NavigationGuardReturn | Promise +} +``` + +### Parameters + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| to | [`RouteLocationNormalized`](#routelocationnormalized) | Route location we are navigating to | +| from | [`RouteLocationNormalized`](#routelocationnormalized) | Route location we are navigating from | +| next | [`NavigationGuardNext`](#navigationguardnext) | Callback to call to accept or reject the navigation. Can also be omitted as long as the navigation guard returns a value instead of calling `next`. | + +### Can return + +It can return any value that can be passed to `next` as long as it is omitted from the list of arguments. + +- `boolean`: Return `true` to accept the navigation or `false` to reject it. +- a [route location](#routelocation) to redirect somewhere else. +- `undefined` (or no `return`). Same as returning `true` diff --git a/docs/api/vue-router-variable.md b/docs/api/vue-router-variable.md index 81fae9da..69efaba4 100644 --- a/docs/api/vue-router-variable.md +++ b/docs/api/vue-router-variable.md @@ -3,27 +3,3 @@ ## RouterLink ## RouterView - -## START_LOCATION - -Initial route location where the router is. Can be used in navigation guards to differentiate the initial navigation. - -**Signature:** -```typescript -START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded -``` - -### Examples - - -```js -import { START_LOCATION } from 'vue-router' - -router.beforeEach((to, from) => { - if (from === START_LOCATION) { - // initial navigation - } -}) -``` - -