mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] router: navigate now returns more information
This commit is contained in:
@@ -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 path = this.destToPath(to);
|
||||||
const initialName = this.currentRouteName;
|
const initialName = this.currentRouteName;
|
||||||
const result = await this.matchAndApplyRules(path);
|
const result = await this.matchAndApplyRules(path);
|
||||||
@@ -123,7 +123,9 @@ export class Router {
|
|||||||
}
|
}
|
||||||
if (this.currentRouteName !== initialName) {
|
if (this.currentRouteName !== initialName) {
|
||||||
this.env.qweb.forceUpdate();
|
this.env.qweb.forceUpdate();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
destToPath(dest: Destination): string {
|
destToPath(dest: Destination): string {
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ describe("beforeRouteEnter", () => {
|
|||||||
await router.start();
|
await router.start();
|
||||||
await router.navigate({ to: "routea" });
|
await router.navigate({ to: "routea" });
|
||||||
expect(window.location.pathname).toBe("/some/patha");
|
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(guard).toBeCalledTimes(1);
|
||||||
expect(window.location.pathname).toBe("/some/patha");
|
expect(window.location.pathname).toBe("/some/patha");
|
||||||
expect(router.currentRouteName).toBe("routea");
|
expect(router.currentRouteName).toBe("routea");
|
||||||
@@ -154,7 +155,8 @@ describe("beforeRouteEnter", () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
await router.start();
|
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");
|
expect(window.location.pathname).toBe("/some/patha");
|
||||||
await router.navigate({ to: "routeb" });
|
await router.navigate({ to: "routeb" });
|
||||||
expect(guard).toBeCalledTimes(1);
|
expect(guard).toBeCalledTimes(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user