*/
exactActiveClass?: string
/**
- * Value passed to the attribute `aria-current` when the link is exact active. Defaults to "page"
+ * Value passed to the attribute `aria-current` when the link is exact active.
+ *
+ * @defaultValue 'page'
*/
ariaCurrentValue?:
| 'page'
: null,
href: link.href,
// this would override user added attrs but Vue will still add
- // the listener so we end up triggering both
+ // the listener, so we end up triggering both
onClick: link.navigate,
class: elClass.value,
},
export const RouterLink: _RouterLinkI = RouterLinkImpl as any
/**
- * Typed version of the `RouterLink` component. Its generic defaults to the typed router so it can be inferred
+ * Typed version of the `RouterLink` component. Its generic defaults to the typed router, so it can be inferred
* automatically for JSX.
*
* @internal
// this will update the instance for new instances as well as reused
// instances when navigating to a new route
to.instances[name] = instance
- // the component instance is reused for a different route or name so
+ // the component instance is reused for a different route or name, so
// we copy any saved update or leave guards. With async setup, the
// mounting component will mount before the matchedRoute changes,
// making instance === oldInstance, so we check if guards have been
* On top of that, the RFC3986 (https://tools.ietf.org/html/rfc3986#section-2.2)
* defines some extra characters to be encoded. Most browsers do not encode them
* in encodeURI https://github.com/whatwg/url/issues/369, so it may be safer to
- * also encode `!'()*`. Leaving unencoded only ASCII alphanumeric(`a-zA-Z0-9`)
+ * also encode `!'()*`. Leaving un-encoded only ASCII alphanumeric(`a-zA-Z0-9`)
* plus `-._~`. This extra safety should be applied to query by patching the
* string returned by encodeURIComponent encodeURI also encodes `[\]^`. `\`
* should be encoded to avoid ambiguity. Browsers (IE, FF, C) transform a `\`
* application/x-www-form-urlencoded
* (https://url.spec.whatwg.org/#urlencoded-parsing) and most browsers seems lo
* leave the plus character as is in queries. To be more flexible, we allow the
- * plus character on the query but it can also be manually encoded by the user.
+ * plus character on the query, but it can also be manually encoded by the user.
*
* Resources:
* - https://url.spec.whatwg.org/#urlencoded-parsing
* @internal
*/
export const enum ErrorTypes {
- // they must be literals to be used as values so we can't write
+ // they must be literals to be used as values, so we can't write
// 1 << 2
MATCHER_NOT_FOUND = 1,
NAVIGATION_GUARD_REDIRECT = 2,
: NavigationGuardWithThis<undefined>
/**
- * Guard called whenever the route that renders this component has changed but
+ * Guard called whenever the route that renders this component has changed, but
* it is reused for the new route. This allows you to guard for changes in
* params, the query or the hash.
*
export type HistoryLocation = string
/**
* Allowed variables in HTML5 history state. Note that pushState clones the state
- * passed and does not accept everything: e.g it doesn't accept symbols, nor
+ * passed and does not accept everything: e.g.: it doesn't accept symbols, nor
* functions as values. It also ignores Symbols as keys.
*
* @internal
export interface RouterHistory {
/**
* Base path that is prepended to every url. This allows hosting an SPA at a
- * subfolder of a domain like `example.com/subfolder` by having a `base` of
- * `/subfolder`
+ * sub-folder of a domain like `example.com/sub-folder` by having a `base` of
+ * `/sub-folder`
*/
readonly base: string
/**
}
function listen(callback: NavigationCallback) {
- // setup the listener and prepare teardown callbacks
+ // set up the listener and prepare teardown callbacks
listeners.push(callback)
const teardown = () => {
window.removeEventListener('beforeunload', beforeUnloadListener)
}
- // setup the listeners and prepare teardown callbacks
+ // set up the listeners and prepare teardown callbacks
window.addEventListener('popstate', popStateHandler)
window.addEventListener('beforeunload', beforeUnloadListener)
// the length is off by one, we need to decrease it
position: history.length - 1,
replaced: true,
- // don't add a scroll as the user may have an anchor and we want
+ // don't add a scroll as the user may have an anchor, and we want
// scrollBehavior to be triggered without a saved position
scroll: null,
},
replace: boolean
): void {
/**
- * if a base tag is provided and we are on a normal domain, we have to
+ * if a base tag is provided, and we are on a normal domain, we have to
* respect the provided `base` attribute because pushState() will use it and
* potentially erase anything before the `#` like at
* https://github.com/vuejs/router/issues/685 where a base of
} from './common'
/**
- * Creates a in-memory based history. The main purpose of this history is to handle SSR. It starts in a special location that is nowhere.
+ * Creates an in-memory based history. The main purpose of this history is to handle SSR. It starts in a special location that is nowhere.
* It's up to the user to replace that location with the starter location by either calling `router.push` or `router.replace`.
*
* @param base - Base applied to all urls, defaults to '/'
path.replace(TRAILING_SLASH_RE, '')
/**
- * Transforms an URI into a normalized history location
+ * Transforms a URI into a normalized history location
*
* @param parseQuery
* @param location - URI to normalize
}
/**
- * Strips off the base from the beginning of a location.pathname in a non
- * case-sensitive way.
+ * Strips off the base from the beginning of a location.pathname in a non-case-sensitive way.
*
* @param pathname - location.pathname
* @param base - base to strip off
if (segment === '.') continue
// go up in the from array
if (segment === '..') {
- // we can't go below zero but we still need to increment toPosition
+ // we can't go below zero, but we still need to increment toPosition
if (position > 1) position--
// continue
}
- // we reached a non relative path, we stop here
+ // we reached a non-relative path, we stop here
else break
}
)
}
- // create the object before hand so it can be passed to children
+ // create the object beforehand, so it can be passed to children
matcher = createRouteRecordMatcher(normalizedRecord, parent, options)
if (__DEV__ && parent && path[0] === '/')
checkMissingParamsInAbsolutePath(matcher, parent)
- // if we are an alias we must tell the original record that we exist
+ // if we are an alias we must tell the original record that we exist,
// so we can be removed
if (originalRecord) {
originalRecord.alias.push(matcher)
}
// if there was no original record, then the first one was not an alias and all
- // other alias (if any) need to reference this record when adding children
+ // other aliases (if any) need to reference this record when adding children
originalRecord = originalRecord || matcher
// TODO: add normalized records for more flexibility
record: RouteRecordRaw
): Record<string, _RouteRecordProps> {
const propsObject = {} as Record<string, _RouteRecordProps>
- // props does not exist on redirect records but we can set false directly
+ // props does not exist on redirect records, but we can set false directly
const props = record.props || false
if ('component' in record) {
propsObject.default = props
*/
export interface _PathParserOptions {
/**
- * Makes the RegExp case sensitive. Defaults to false
+ * Makes the RegExp case-sensitive.
+ *
+ * @defaultValue false
*/
sensitive?: boolean
/**
- * Should we disallow a trailing slash. Defaults to false
+ * Whether to disallow a trailing slash or not.
+ *
+ * @defaultValue false
*/
strict?: boolean
/**
- * Should the RegExp match from the beginning by prepending a `^` to it. Defaults to true
+ * Should the RegExp match from the beginning by prepending a `^` to it.
* @internal
+ *
+ * @defaultValue true
*/
start?: boolean
/**
- * Should the RegExp match until the end by appending a `$` to it. Defaults to true
+ * Should the RegExp match until the end by appending a `$` to it.
+ *
+ * @defaultValue true
*/
end?: boolean
}
'end' | 'sensitive' | 'strict'
>
-// default pattern for a param: non greedy everything but /
+// default pattern for a param: non-greedy everything but /
const BASE_PARAM_PATTERN = '[^/]+?'
const BASE_PATH_PARSER_OPTIONS: Required<_PathParserOptions> = {
if (options.strict && !segment.length) pattern += '/'
for (let tokenIndex = 0; tokenIndex < segment.length; tokenIndex++) {
const token = segment[tokenIndex]
- // resets the score if we are inside a sub segment /:a-other-:b
+ // resets the score if we are inside a sub-segment /:a-other-:b
let subSegmentScore: number =
PathScore.Segment +
(options.sensitive ? PathScore.BonusCaseSensitive : 0)
* views.
*/
instances: Record<string, ComponentPublicInstance | undefined | null>
- // can only be of of the same type as this record
+ // can only be of the same type as this record
/**
* Defines if this record is the alias of another one. This property is
* `undefined` if the record is the original one.
if (!activeRecord) {
__DEV__ &&
warn(
- 'No active route record was found when calling `onBeforeRouteLeave()`. Make sure you call this function inside of a component child of <router-view>. Maybe you called it inside of App.vue?'
+ 'No active route record was found when calling `onBeforeRouteLeave()`. Make sure you call this function inside a component child of <router-view>. Maybe you called it inside of App.vue?'
)
return
}
if (!activeRecord) {
__DEV__ &&
warn(
- 'No active route record was found when calling `onBeforeRouteUpdate()`. Make sure you call this function inside of a component child of <router-view>. Maybe you called it inside of App.vue?'
+ 'No active route record was found when calling `onBeforeRouteUpdate()`. Make sure you call this function inside a component child of <router-view>. Maybe you called it inside of App.vue?'
)
return
}
}
/**
- * Ensures a route is loaded so it can be passed as o prop to `<RouterView>`.
+ * Ensures a route is loaded, so it can be passed as o prop to `<RouterView>`.
*
* @param route - resolved route to load
*/
*/
linkExactActiveClass?: string
/**
- * Default class applied to non active {@link RouterLink}. If none is provided,
+ * Default class applied to non-active {@link RouterLink}. If none is provided,
* `router-link-inactive` will be applied.
*/
// linkInactiveClass?: string
/**
* Returns the {@link RouteLocation | normalized version} of a
* {@link RouteLocationRaw | route location}. Also includes an `href` property
- * that includes any existing `base`. By default the `currentLocation` used is
+ * that includes any existing `base`. By default, the `currentLocation` used is
* `route.currentRoute` and should only be overridden in advanced use cases.
*
* @param to - Raw route location to resolve
delete targetParams[key]
}
}
- // pass encoded values to the matcher so it can produce encoded path and fullPath
+ // pass encoded values to the matcher, so it can produce encoded path and fullPath
matcherLocation = assign({}, rawLocation, {
params: encodeParams(rawLocation.params),
})
)
}
- // decoding them) the matcher might have merged current location params so
+ // the matcher might have merged current location params, so
// we need to run the decoding again
matchedRoute.params = normalizeParams(decodeParams(matchedRoute.params))
// keep options
assign(
{
- // preserve an existing replace but allow the redirect to override it
+ // preserve an existing replacement but allow the redirect to override it
replace,
},
locationAsObject(failure.to),
// Here we could call if (info.delta) routerHistory.go(-info.delta,
// false) but this is bug prone as we have no way to wait the
// navigation to be finished before calling pushWithRedirect. Using
- // a setTimeout of 16ms seems to work but there is not guarantee for
+ // a setTimeout of 16ms seems to work but there is no guarantee for
// it to work on every browser. So instead we do not restore the
// history entry and trigger a new navigation as requested by the
// navigation guard.
)
.then(failure => {
// manual change in hash history #916 ending up in the URL not
- // changing but it was changed by the manual url change, so we
+ // changing, but it was changed by the manual url change, so we
// need to manually change it ourselves
if (
isNavigationFailure(
export interface RouteLocationNormalizedLoaded extends _RouteLocationBase {
/**
* Array of {@link RouteLocationMatched} containing only plain components (any
- * lazy-loaded components have been loaded and were replaced inside of the
+ * lazy-loaded components have been loaded and were replaced inside the
* `components` object) so it can be directly used to display routes. It
* cannot contain redirect records either
*/
redirectedFrom: undefined,
}
-// make matched non enumerable for easy printing
+// make matched non-enumerable for easy printing
// NOTE: commented for tests at RouterView.spec
// Object.defineProperty(START_LOCATION_NORMALIZED, 'matched', {
// enumerable: false,
params: RouteParams
/**
- * Merged `meta` properties from all of the matched route records.
+ * Merged `meta` properties from all the matched route records.
*/
meta: RouteMeta