From: Eduardo San Martin Morote Date: Fri, 11 Sep 2020 16:15:45 +0000 (+0200) Subject: docs(api): navigation guard X-Git-Tag: v4.0.0-beta.10~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b58e0aabbaf303367dd4c0d825e66509b68408fa;p=thirdparty%2Fvuejs%2Frouter.git docs(api): navigation guard --- diff --git a/docs/api/index.md b/docs/api/index.md index 91be993f..c5a09ec6 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -880,66 +880,44 @@ Array of [normalized route records](#routerecord). ## NavigationFailure -Extended Error that contains extra information regarding a failed navigation. - -**Signature:** - -```typescript -export interface NavigationFailure extends RouterErrorBase -``` - ### from -Route location we were navigating from - -**Signature:** +- **Type**: [`RouteLocationNormalized`](#routelocationnormalized) +- **Details**: -```typescript -from: RouteLocationNormalized -``` + Route location we were navigating from ### to -Route location we were navigating to - -**Signature:** +- **Type**: [`RouteLocationNormalized`](#routelocationnormalized) +- **Details**: -```typescript -to: RouteLocationNormalized -``` + Route location we were navigating to ### type -Type of the navigation. One of [NavigationFailureType](#navigationfailuretype) +- **Type**: [`NavigationFailureType`](#navigationfailuretype) +- **Details**: -## NavigationGuard + Type of the navigation failure. -Navigation guard. See [Navigation Guards](/guide/advanced/navigation-guards.md). +- **See Also**: [Navigation Failures](/guide/advanced/navigation-failures.md) -**Signature:** +## NavigationGuard -```typescript -export interface NavigationGuard { - ( - to: RouteLocationNormalized, - from: RouteLocationNormalized, - next: NavigationGuardNext - ): NavigationGuardReturn | Promise -} -``` +- **Arguments**: -### Parameters + - [`RouteLocationNormalized`](#routelocationnormalized) to - Route location we are navigating to + - [`RouteLocationNormalized`](#routelocationnormalized) from - Route location we are navigating from + - `Function` next (Optional) - Callback to validate the navigation -| 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`. | +- **Details**: -### Can return + Function that can be passed to control a router navigation. The `next` callback can be omitted if you return a value (or a Promise) instead, which is encouraged. Possible return values (and parameters for `next`) are: -It can return any value that can be passed to `next` as long as it is omitted from the list of arguments. + - `undefined | void | true`: validates the navigation + - `false`: cancels the navigation + - [`RouteLocationRaw`](#routelocationraw): redirects to a different location + - `(vm: ComponentPublicInstance) => any` **only for `beforeRouteEnter`**: A callback to be executed once the navigation completes. Receives the route component instance as the parameter. -- `boolean`: Return `true` to accept the navigation or `false` to reject it. -- a [route location](#routelocationraw) to redirect somewhere else. -- `undefined` (or no `return`). Same as returning `true` +- **See Also**: [Navigation Guards](/guide/advanced/navigation-guards.md)