})
})
- it('can await router.go', async () => {
- const { router } = await newRouter()
- await router.push('/foo')
- let currentRoute = router.currentRoute.value
- const [p1, r1] = fakePromise()
- router.beforeEach(async (to, from, next) => {
- await p1
- next()
- })
- let p = router.go(-1)
- expect(router.currentRoute.value).toBe(currentRoute)
- r1()
- // resolves to undefined as a working navigation
- await expect(p).resolves.toBe(undefined)
- expect(router.currentRoute.value).not.toBe(currentRoute)
- })
-
it('can pass replace option to push', async () => {
const { router, history } = await newRouter()
jest.spyOn(history, 'replace')
replace(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>
/**
* Go back in history if possible by calling `history.back()`. Equivalent to
- * `router.go(-1)`. Returns a Promise. See the limitations at
- * {@link Router.go}.
+ * `router.go(-1)`.
*/
- back(): Promise<NavigationFailure | void | undefined>
+ back(): ReturnType<Router['go']>
/**
* Go forward in history if possible by calling `history.forward()`.
- * Equivalent to `router.go(1)`. Returns a Promise. See the limitations at
- * {@link Router.go}.
+ * Equivalent to `router.go(1)`.
*/
- forward(): Promise<NavigationFailure | void | undefined>
+ forward(): ReturnType<Router['go']>
/**
- * Allows you to move forward or backward through the history. Returns a
- * Promise that resolves when the navigation finishes. If it wasn't possible
- * to go back, the promise never resolves or rejects
+ * Allows you to move forward or backward through the history. Calls
+ * `history.go()`.
*
* @param delta - The position in the history to which you want to move,
* relative to the current page
*/
- go(delta: number): Promise<NavigationFailure | void | undefined>
+ go(delta: number): void
/**
* Add a navigation guard that executes before any navigation. Returns a
.catch(triggerError)
}
- function go(delta: number) {
- return new Promise<NavigationFailure | void | undefined>(
- (resolve, reject) => {
- let removeError = errorHandlers.add(err => {
- removeError()
- removeAfterEach()
- reject(err)
- })
- let removeAfterEach = afterGuards.add((_to, _from, failure) => {
- removeError()
- removeAfterEach()
- resolve(failure)
- })
-
- routerHistory.go(delta)
- }
- )
- }
+ const go = (delta: number) => routerHistory.go(delta)
let started: boolean | undefined
const installedApps = new Set<App>()