diff --git a/src/router/Router.ts b/src/router/Router.ts index 43fef785..aa9c3411 100644 --- a/src/router/Router.ts +++ b/src/router/Router.ts @@ -108,7 +108,7 @@ export class Router { } } - async navigate(to: Destination): Promise { + async navigate(to: Destination): Promise { const path = this.destToPath(to); const initialName = this.currentRouteName; const result = await this.matchAndApplyRules(path); @@ -123,7 +123,9 @@ export class Router { } if (this.currentRouteName !== initialName) { this.env.qweb.forceUpdate(); + return true; } + return false; } destToPath(dest: Destination): string { diff --git a/tests/router/router.test.ts b/tests/router/router.test.ts index 86a7f4b1..680f47f8 100644 --- a/tests/router/router.test.ts +++ b/tests/router/router.test.ts @@ -138,7 +138,8 @@ describe("beforeRouteEnter", () => { await router.start(); await router.navigate({ to: "routea" }); expect(window.location.pathname).toBe("/some/patha"); - await router.navigate({ to: "routeb" }); + const result = await router.navigate({ to: "routeb" }); + expect(result).toBe(false); expect(guard).toBeCalledTimes(1); expect(window.location.pathname).toBe("/some/patha"); expect(router.currentRouteName).toBe("routea"); @@ -154,7 +155,8 @@ describe("beforeRouteEnter", () => { ]); await router.start(); - await router.navigate({ to: "routea" }); + const result = await router.navigate({ to: "routea" }); + expect(result).toBe(true); expect(window.location.pathname).toBe("/some/patha"); await router.navigate({ to: "routeb" }); expect(guard).toBeCalledTimes(1);