[IMP] router: navigate now returns more information

This commit is contained in:
Géry Debongnie
2019-08-06 07:48:58 +02:00
parent 3db6f0a643
commit aa268937a7
2 changed files with 7 additions and 3 deletions
+3 -1
View File
@@ -108,7 +108,7 @@ export class Router {
}
}
async navigate(to: Destination): Promise<void> {
async navigate(to: Destination): Promise<boolean> {
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 {
+4 -2
View File
@@ -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);