history.push(loc)
history.back()
expect(spy).toHaveBeenCalledTimes(1)
- expect(spy).toHaveBeenCalledWith(START, normaliezedLoc, { type: 'back' })
+ expect(spy).toHaveBeenCalledWith(START, normaliezedLoc, { direction: 'back' })
history.forward()
expect(spy).toHaveBeenCalledTimes(2)
expect(spy).toHaveBeenLastCalledWith(normaliezedLoc, START, {
- type: 'forward',
+ direction: 'forward',
})
})
// @ts-ignore
window.r = r
-h.listen((to, from, { type }) => {
- console.log(`popstate(${type})`, { to, from })
+h.listen((to, from, { direction }) => {
+ console.log(`popstate(${direction})`, { to, from })
})
async function run() {
BaseHistory,
HistoryLocation,
HistoryLocationNormalized,
- NavigationType,
+ NavigationDirection,
} from './base'
import { NavigationCallback, HistoryState, START } from './base'
back() {
const from = this.location
if (this.position > 0) this.position--
- this.triggerListeners(this.location, from, { type: NavigationType.back })
+ this.triggerListeners(this.location, from, {
+ direction: NavigationDirection.back,
+ })
}
forward() {
const from = this.location
if (this.position < this.queue.length - 1) this.position++
- this.triggerListeners(this.location, from, { type: NavigationType.forward })
+ this.triggerListeners(this.location, from, {
+ direction: NavigationDirection.forward,
+ })
}
destroy() {
private triggerListeners(
to: HistoryLocationNormalized,
from: HistoryLocationNormalized,
- { type }: { type: NavigationType }
+ { direction }: { direction: NavigationDirection }
): void {
- const info = { type }
+ const info = { direction }
for (let callback of this.listeners) {
callback(to, from, info)
}
hash: '',
}
-export enum NavigationType {
+export enum NavigationDirection {
// NOTE: is it better to have strings?
back = 'back',
forward = 'forward',
(
to: HistoryLocationNormalized,
from: HistoryLocationNormalized,
- info: { type: NavigationType }
+ info: { direction: NavigationDirection }
): void
}
import consola from 'consola'
import { BaseHistory, HistoryLocationNormalized, HistoryLocation } from './base'
-import { NavigationCallback, HistoryState, NavigationType } from './base'
+import { NavigationCallback, HistoryState, NavigationDirection } from './base'
const cs = consola.withTag('html5')
// call all listeners
const navigationInfo = {
- type:
+ direction:
state.forward && from.fullPath === state.forward.fullPath
- ? NavigationType.back
- : NavigationType.forward,
+ ? NavigationDirection.back
+ : NavigationDirection.forward,
}
this._listeners.forEach(listener =>
listener(this.location, from, navigationInfo)
import {
BaseHistory,
HistoryLocationNormalized,
- NavigationType,
+ NavigationDirection,
} from './history/base'
import { RouterMatcher } from './matcher'
import {
} else {
// TODO: handle abort and redirect correctly
// if we were going back, we push and discard the rest of the history
- if (info.type === NavigationType.back) {
+ if (info.direction === NavigationDirection.back) {
this.history.push(from)
} else {
// TODO: go back because we cancelled, then