]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs(api): types
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 8 Sep 2020 16:25:20 +0000 (18:25 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 8 Sep 2020 16:25:20 +0000 (18:25 +0200)
docs/api/index.md
docs/api/vue-router-variable.md

index 5a792ea7d13fbacb0dc271f1ef72fa23b57343f2..531270ff29049fa1495d7cf02b4f33b47e0ba24d 100644 (file)
@@ -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<NavigationGuardReturn>
+}
+```
+
+### 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`
index 81fae9da2e6b33d0416b5be838101f2c07d17de2..69efaba40e5db6201094835f1fe23d2f68e5e982 100644 (file)
@@ -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
-  }
-})
-```
-
-