import { BaseHistory } from './history/base'
import { PluginFunction, VueConstructor } from 'vue'
import createHistory from './history/html5.2'
+import createMemoryHistory from './history/abstract.2'
import View from './components/View'
import Link from './components/Link'
// abstract: AbstractHistory
// }
-export { createHistory }
+export { createHistory, createMemoryHistory }
export default class VueRouter extends Router {
static install = plugin
RouterHistory,
stringifyURL,
normalizeQuery,
- HistoryLocationNormalized
+ HistoryLocationNormalized,
+ START,
} from './history/common'
import { RouterMatcher } from './matcher'
import {
PostNavigationGuard,
Lazy,
MatcherLocation,
- RouteQueryAndHash
+ RouteQueryAndHash,
} from './types/index'
import {
ScrollToPosition,
ScrollPosition,
- scrollToPosition
+ scrollToPosition,
} from './utils/scroll'
import { guardToPromiseFn, extractComponentsGuards } from './utils'
import {
NavigationGuardRedirect,
NavigationAborted,
- NavigationCancelled
+ NavigationCancelled,
} from './errors'
interface ScrollBehavior {
// accept current navigation
this.currentRoute = {
...to,
- ...matchedRoute
+ ...matchedRoute,
}
this.updateReactiveRoute()
// TODO: refactor with a state getter
// TODO: refactor with url utils
query: {},
hash: '',
- ...to
+ ...to,
})
}
fullPath: stringifyURL({
path: matchedRoute.normalizedLocation.path,
query: location.query,
- hash: location.hash
+ hash: location.hash,
}),
query: normalizeQuery(location.query || {}),
hash: location.hash,
redirectedFrom,
- meta: {}
+ meta: {},
}
if (typeof redirect === 'string') {
{
...newLocation,
query: normalizeQuery(newLocation.query || {}),
- hash: newLocation.hash || ''
+ hash: newLocation.hash || '',
},
currentLocation,
normalizedLocation
{
...redirect,
query: normalizeQuery(redirect.query || {}),
- hash: redirect.hash || ''
+ hash: redirect.hash || '',
},
currentLocation,
normalizedLocation
const url = normalizeLocation({
path: matchedRoute.path,
query: location.query,
- hash: location.hash
+ hash: location.hash,
})
return {
...matchedRoute,
...url,
- redirectedFrom
+ redirectedFrom,
}
}
}
url = normalizeLocation({
query,
hash,
- ...location
+ ...location,
})
}
private updateReactiveRoute() {
if (!this.app) return
+ this.markAsReady()
// TODO: matched should be non enumerable and the defineProperty here shouldn't be necessary
const route = { ...this.currentRoute }
Object.defineProperty(route, 'matched', { enumerable: false })
this.ready = true
}
- async doInitialNavigation(): Promise<RouteLocationNormalized> {
+ async doInitialNavigation(): Promise<void> {
+ if (this.history.location === START) return
+ console.log('doing initial navigation')
// TODO: refactor code that was duplicated from push method
const toLocation: RouteLocationNormalized = this.resolveLocation(
this.history.location,
throw new NavigationCancelled(toLocation, this.currentRoute)
}
// TODO: setup redirect stack
- return this.push(error.to)
+ await this.push(error.to)
+ return
} else {
// TODO: write tests
// triggerError as well
for (const guard of this.afterGuards) guard(toLocation, from)
this.markAsReady()
- return this.currentRoute
}
private async handleScroll(