Skip to content

Commit 31cf069

Browse files
committed
docs(api): adding docs to source code
1 parent 4999db9 commit 31cf069

File tree

9 files changed

+241
-37
lines changed

9 files changed

+241
-37
lines changed

src/errors.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,46 @@ export interface MatcherError extends RouterErrorBase {
3434
currentLocation?: MatcherLocation
3535
}
3636

37+
/**
38+
* Enumeration with all possible types for navigation failures. Can be passed to
39+
* {@link isNavigationFailure} to check for specific failures.
40+
*/
3741
export enum NavigationFailureType {
42+
/**
43+
* An aborted navigation is a navigation that failed because a navigation
44+
* guard returned `false` or called `next(false)`
45+
*/
3846
aborted = ErrorTypes.NAVIGATION_ABORTED,
47+
/**
48+
* A cancelled navigation is a navigation that failed because a more recent
49+
* navigation finished started (not necessarily finished).
50+
*/
3951
cancelled = ErrorTypes.NAVIGATION_CANCELLED,
52+
/**
53+
* A duplicated navigation is a navigation that failed because it was
54+
* initiated while already being at the exact same ___location.
55+
*/
4056
duplicated = ErrorTypes.NAVIGATION_DUPLICATED,
4157
}
58+
59+
/**
60+
* Extended Error that contains extra information regarding a failed navigation.
61+
*/
4262
export interface NavigationFailure extends RouterErrorBase {
63+
/**
64+
* Type of the navigation. One of {@link NavigationFailureType}
65+
*/
4366
type:
4467
| ErrorTypes.NAVIGATION_CANCELLED
4568
| ErrorTypes.NAVIGATION_ABORTED
4669
| ErrorTypes.NAVIGATION_DUPLICATED
70+
/**
71+
* Route ___location we were navigating from
72+
*/
4773
from: RouteLocationNormalized
74+
/**
75+
* Route ___location we were navigating to
76+
*/
4877
to: RouteLocationNormalized
4978
}
5079

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export {
3434
RouteRecordRaw,
3535
NavigationGuard,
3636
NavigationGuardNext,
37-
PostNavigationGuard,
37+
NavigationHookAfter,
3838
} from './types'
3939
export {
4040
createRouter,

src/___location.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ export function stripBase(pathname: string, base: string): string {
116116
* pointing towards the same {@link RouteRecord} and that all `params`, `query`
117117
* parameters and `hash` are the same
118118
*
119-
* @param a first {@link RouteLocation}
120-
* @param b second {@link RouteLocation}
119+
* @param a - first {@link RouteLocation}
120+
* @param b - second {@link RouteLocation}
121121
*/
122122
export function isSameRouteLocation(
123123
stringifyQuery: (query: LocationQueryRaw) => string,
@@ -141,8 +141,8 @@ export function isSameRouteLocation(
141141
* Check if two `RouteRecords` are equal. Takes into account aliases: they are
142142
* considered equal to the `RouteRecord` they are aliasing.
143143
*
144-
* @param a first {@link RouteRecord}
145-
* @param b second {@link RouteRecord}
144+
* @param a - first {@link RouteRecord}
145+
* @param b - second {@link RouteRecord}
146146
*/
147147
export function isSameRouteRecord(a: RouteRecord, b: RouteRecord): boolean {
148148
// since the original record has an undefined value for aliasOf

src/matcher/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function isAliasRecord(record: RouteRecordMatcher | undefined): boolean {
379379
/**
380380
* Merge meta fields of an array of records
381381
*
382-
* @param matched array of matched records
382+
* @param matched - array of matched records
383383
*/
384384
function mergeMetaFields(matched: MatcherLocation['matched']) {
385385
return matched.reduce(

src/matcher/pathParserRanker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export interface PathParser {
4444
stringify(params: PathParams): string
4545
}
4646

47+
/**
48+
* @internal
49+
*/
4750
export interface _PathParserOptions {
4851
/**
4952
* Makes the RegExp case sensitive. Defaults to false
@@ -54,11 +57,12 @@ export interface _PathParserOptions {
5457
*/
5558
strict?: boolean
5659
/**
57-
* Should the RegExp match from the beginning by prepending a ^. Defaults to true
60+
* Should the RegExp match from the beginning by prepending a `^` to it. Defaults to true
61+
* @internal
5862
*/
5963
start?: boolean
6064
/**
61-
* Should the RegExp match until the end by appending a $. Defaults to true
65+
* Should the RegExp match until the end by appending a `$` to it. Defaults to true
6266
*/
6367
end?: boolean
6468
}

src/matcher/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
import { ComponentPublicInstance } from 'vue'
99

1010
// normalize component/components into components and make every property always present
11+
/**
12+
* Normalized version of a {@link RouteRecord | Route Record}
13+
*/
1114
export interface RouteRecordNormalized {
1215
/**
1316
* {@inheritDoc _RouteRecordBase.path}
@@ -77,4 +80,7 @@ export interface RouteRecordNormalized {
7780
aliasOf: RouteRecordNormalized | undefined
7881
}
7982

83+
/**
84+
* {@inheritDoc RouteRecordNormalized}
85+
*/
8086
export type RouteRecord = RouteRecordNormalized

src/navigationGuards.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function registerGuard(list: NavigationGuard[], guard: NavigationGuard) {
4141
}
4242

4343
/**
44-
* Add a navigation guard that triggers whenever the current ___location is
45-
* left. Similarly to {@link beforeRouteLeave}, it has access to the
46-
* component instance as `this`.
44+
* Add a navigation guard that triggers whenever the component for the current
45+
* ___location is about to be left. Similar to {@link beforeRouteLeave} but can be
46+
* used in any component. The guard is removed when the component is unmounted.
4747
*
4848
* @param leaveGuard - {@link NavigationGuard}
4949
*/
@@ -68,9 +68,9 @@ export function onBeforeRouteLeave(leaveGuard: NavigationGuard) {
6868
}
6969

7070
/**
71-
* Add a navigation guard that triggers whenever the current ___location is
72-
* updated. Similarly to {@link beforeRouteUpdate}, it has access to the
73-
* component instance as `this`.
71+
* Add a navigation guard that triggers whenever the current ___location is about
72+
* to be updated. Similar to {@link beforeRouteUpdate} but can be used in any
73+
* component. The guard is removed when the component is unmounted.
7474
*
7575
* @param updateGuard - {@link NavigationGuard}
7676
*/

0 commit comments

Comments
 (0)