[REF] router: change Destination shape

This commit is contained in:
Géry Debongnie
2019-07-25 23:06:15 +02:00
parent cd0762b436
commit bb46346767
2 changed files with 7 additions and 7 deletions
+3 -3
View File
@@ -18,8 +18,8 @@ export interface RouterEnv extends Env {
}
export interface Destination {
to?: string;
route?: string;
path?: string;
name?: string;
params?: RouteParams;
}
@@ -74,7 +74,7 @@ export class Router {
}
destToUrl(dest: Destination): string {
return dest.to || this.routeToURL(this.routes[dest.route!].path, dest.params!);
return dest.path || this.routeToURL(this.routes[dest.name!].path, dest.params!);
}
get currentRouteName(): string | null{
+4 -4
View File
@@ -43,12 +43,12 @@ describe("router directive t-routecomponent", () => {
];
const router = new Router(env,routes, {mode: 'history'})
router.navigate({ route: "about" });
router.navigate({ name: "about" });
const app = new App(env);
await app.mount(fixture);
expect(fixture.innerHTML).toBe("<div><span>About</span></div>");
router.navigate({ route: "users" });
router.navigate({ name: "users" });
await nextTick();
expect(fixture.innerHTML).toBe("<div><span>Users</span></div>");
expect(env.qweb.templates.App.fn.toString()).toMatchSnapshot();
@@ -70,7 +70,7 @@ describe("router directive t-routecomponent", () => {
const routes = [{ name: "book", path: "/book/{{title}}", component: Book }];
const router = new Router(env,routes, {mode: 'history'})
router.navigate({ route: "book", params: { title: "1984" } });
router.navigate({ name: "book", params: { title: "1984" } });
const app = new App(env);
await app.mount(fixture);
expect(fixture.innerHTML).toBe("<div><span>Book 1984</span></div>");
@@ -97,7 +97,7 @@ describe("router directive t-routecomponent", () => {
const routes = [{ name: "book", path: "/book/{{title}}/{{val.number}}", component: Book }];
const router = new Router(env,routes, {mode: 'history'})
router.navigate({ route: "book", params: { title: "1984", val: "123" } });
router.navigate({ name: "book", params: { title: "1984", val: "123" } });
const app = new App(env);
await app.mount(fixture);
expect(fixture.innerHTML).toBe("<div><span>Book 1984|124</span></div>");