From 16926b48febda8a5e25e1223cdf8395608239a80 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 8 Sep 2020 18:25:20 +0200 Subject: [PATCH] docs(api): types --- docs/api/index.md | 54 +++++++++++++++++++++++++++++++++ docs/api/vue-router-variable.md | 24 --------------- 2 files changed, 54 insertions(+), 24 deletions(-) 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 - } -}) -``` - - -- 2.47.2