mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] router: change Destination shape
This commit is contained in:
@@ -18,8 +18,8 @@ export interface RouterEnv extends Env {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Destination {
|
export interface Destination {
|
||||||
to?: string;
|
path?: string;
|
||||||
route?: string;
|
name?: string;
|
||||||
params?: RouteParams;
|
params?: RouteParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ export class Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destToUrl(dest: Destination): string {
|
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{
|
get currentRouteName(): string | null{
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ describe("router directive t-routecomponent", () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const router = new Router(env,routes, {mode: 'history'})
|
const router = new Router(env,routes, {mode: 'history'})
|
||||||
router.navigate({ route: "about" });
|
router.navigate({ name: "about" });
|
||||||
const app = new App(env);
|
const app = new App(env);
|
||||||
await app.mount(fixture);
|
await app.mount(fixture);
|
||||||
expect(fixture.innerHTML).toBe("<div><span>About</span></div>");
|
expect(fixture.innerHTML).toBe("<div><span>About</span></div>");
|
||||||
|
|
||||||
router.navigate({ route: "users" });
|
router.navigate({ name: "users" });
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("<div><span>Users</span></div>");
|
expect(fixture.innerHTML).toBe("<div><span>Users</span></div>");
|
||||||
expect(env.qweb.templates.App.fn.toString()).toMatchSnapshot();
|
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 routes = [{ name: "book", path: "/book/{{title}}", component: Book }];
|
||||||
const router = new Router(env,routes, {mode: 'history'})
|
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);
|
const app = new App(env);
|
||||||
await app.mount(fixture);
|
await app.mount(fixture);
|
||||||
expect(fixture.innerHTML).toBe("<div><span>Book 1984</span></div>");
|
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 routes = [{ name: "book", path: "/book/{{title}}/{{val.number}}", component: Book }];
|
||||||
const router = new Router(env,routes, {mode: 'history'})
|
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);
|
const app = new App(env);
|
||||||
await app.mount(fixture);
|
await app.mount(fixture);
|
||||||
expect(fixture.innerHTML).toBe("<div><span>Book 1984|124</span></div>");
|
expect(fixture.innerHTML).toBe("<div><span>Book 1984|124</span></div>");
|
||||||
|
|||||||
Reference in New Issue
Block a user