*/
export function createRouter(options: RouterOptions): Router {
const matcher = createRouterMatcher(options.routes, options)
- let parseQuery = options.parseQuery || originalParseQuery
- let stringifyQuery = options.stringifyQuery || originalStringifyQuery
- let routerHistory = options.history
+ const parseQuery = options.parseQuery || originalParseQuery
+ const stringifyQuery = options.stringifyQuery || originalStringifyQuery
+ const routerHistory = options.history
if (__DEV__ && !routerHistory)
throw new Error(
'Provide the "history" option when calling "createRouter()":' +
}
function removeRoute(name: RouteRecordName) {
- let recordMatcher = matcher.getRecordMatcher(name)
+ const recordMatcher = matcher.getRecordMatcher(name)
if (recordMatcher) {
matcher.removeRoute(recordMatcher)
} else if (__DEV__) {
// we create a copy to modify it later
currentLocation = assign({}, currentLocation || currentRoute.value)
if (typeof rawLocation === 'string') {
- let locationNormalized = parseURL(
+ const locationNormalized = parseURL(
parseQuery,
rawLocation,
currentLocation.path
)
- let matchedRoute = matcher.resolve(
+ const matchedRoute = matcher.resolve(
{ path: locationNormalized.path },
currentLocation
)
- let href = routerHistory.createHref(locationNormalized.fullPath)
+ const href = routerHistory.createHref(locationNormalized.fullPath)
if (__DEV__) {
if (href.startsWith('//'))
warn(
currentLocation.params = encodeParams(currentLocation.params)
}
- let matchedRoute = matcher.resolve(matcherLocation, currentLocation)
+ const matchedRoute = matcher.resolve(matcherLocation, currentLocation)
const hash = rawLocation.hash || ''
if (__DEV__ && hash && !hash.startsWith('#')) {
})
)
- let href = routerHistory.createHref(fullPath)
+ const href = routerHistory.createHref(fullPath)
if (__DEV__) {
if (href.startsWith('//')) {
warn(
function setupListeners() {
removeHistoryListener = routerHistory.listen((to, _from, info) => {
// cannot be a redirect route because it was in history
- let toLocation = resolve(to) as RouteLocationNormalized
+ const toLocation = resolve(to) as RouteLocationNormalized
// due to dynamic routing, and to hash history with manual navigation
// (manually changing the url or calling history.hash = '#/somewhere'),
const { scrollBehavior } = options
if (!isBrowser || !scrollBehavior) return Promise.resolve()
- let scrollPosition: _ScrollPositionNormalized | null =
+ const scrollPosition: _ScrollPositionNormalized | null =
(!isPush && getSavedScrollPosition(getScrollKey(to.fullPath, 0))) ||
((isFirstNavigation || !isPush) &&
(history.state as HistoryState) &&
RouteLocationNormalizedLoaded[k]
>
}
- for (let key in START_LOCATION_NORMALIZED) {
+ for (const key in START_LOCATION_NORMALIZED) {
// @ts-expect-error: the key matches
reactiveRoute[key] = computed(() => currentRoute.value[key])
}
app.provide(routeLocationKey, reactive(reactiveRoute))
app.provide(routerViewLocationKey, currentRoute)
- let unmountApp = app.unmount
+ const unmountApp = app.unmount
installedApps.add(app)
app.unmount = function () {
installedApps.delete(app)