Skip to content

Commit 16926b4

Browse files
committed
docs(api): types
1 parent 7f95f86 commit 16926b4

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

docs/api/index.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,28 @@ export declare enum NavigationFailureType
359359
| cancelled | 8 | A cancelled navigation is a navigation that failed because a more recent navigation finished started (not necessarily finished). |
360360
| duplicated | 16 | A duplicated navigation is a navigation that failed because it was initiated while already being at the exact same ___location. |
361361

362+
## START_LOCATION
363+
364+
Initial route ___location where the router is. Can be used in navigation guards to differentiate the initial navigation.
365+
366+
**Signature:**
367+
368+
```typescript
369+
START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded
370+
```
371+
372+
### Examples
373+
374+
```js
375+
import { START_LOCATION } from 'vue-router'
376+
377+
router.beforeEach((to, from) => {
378+
if (from === START_LOCATION) {
379+
// initial navigation
380+
}
381+
})
382+
```
383+
362384
## Composition API
363385

364386
### onBeforeRouteLeave
@@ -408,3 +430,35 @@ TODO:
408430
## TypeScript
409431

410432
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.
433+
434+
## NavigationGuard
435+
436+
Navigation guard. See [Navigation Guards](/guide/advanced/navigation-guards.md).
437+
438+
**Signature:**
439+
440+
```typescript
441+
export interface NavigationGuard {
442+
(
443+
to: RouteLocationNormalized,
444+
from: RouteLocationNormalized,
445+
next: NavigationGuardNext
446+
): NavigationGuardReturn | Promise<NavigationGuardReturn>
447+
}
448+
```
449+
450+
### Parameters
451+
452+
| Parameter | Type | Description |
453+
| --------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
454+
| to | [`RouteLocationNormalized`](#routelocationnormalized) | Route ___location we are navigating to |
455+
| from | [`RouteLocationNormalized`](#routelocationnormalized) | Route ___location we are navigating from |
456+
| 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`. |
457+
458+
### Can return
459+
460+
It can return any value that can be passed to `next` as long as it is omitted from the list of arguments.
461+
462+
- `boolean`: Return `true` to accept the navigation or `false` to reject it.
463+
- a [route ___location](#routelocation) to redirect somewhere else.
464+
- `undefined` (or no `return`). Same as returning `true`

docs/api/vue-router-variable.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,3 @@
33
## RouterLink
44

55
## RouterView
6-
7-
## START_LOCATION
8-
9-
Initial route ___location where the router is. Can be used in navigation guards to differentiate the initial navigation.
10-
11-
**Signature:**
12-
```typescript
13-
START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded
14-
```
15-
16-
### Examples
17-
18-
19-
```js
20-
import { START_LOCATION } from 'vue-router'
21-
22-
router.beforeEach((to, from) => {
23-
if (from === START_LOCATION) {
24-
// initial navigation
25-
}
26-
})
27-
```
28-
29-

0 commit comments

Comments
 (0)