Skip to content

Commit

Permalink
Proper route extending with path params #42 (#43)
Browse files Browse the repository at this point in the history
* Proper route extending with path params #42

* Fixed linting errors

Co-authored-by: Łukasz Kużyński <[email protected]>
  • Loading branch information
wookieb and wookieb authored Jul 15, 2020
1 parent 15f2e8e commit 28907a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/defineRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function defineRoute(...args: any[]): UmbrellaRouteDef {
},
(x) => {
const parentPathArray = asArray(
parent.path(filter(extensionParamNames))
parent.path(filter(parentParamNames))
);
const childPathArray = asArray(path(filter(extensionParamNames)));

Expand Down
20 changes: 20 additions & 0 deletions test/defineRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,24 @@ describe("defineRoute", () => {
"b",
]);
});

it("extending routes with params should merge path", () => {
const fooRoute = defineRoute(
{ a: param.path.string },
(p) => `/foo/${p.a}`
);
const barRoute = fooRoute.extend(
{ b: param.path.string },
(p) => `/bar/${p.b}`
);

expect(Object.keys(barRoute["~internal"].params).sort()).toEqual([
"a",
"b",
]);

expect(barRoute["~internal"].path({ a: "aa", b: "bb" })).toEqual([
"/foo/aa/bar/bb",
]);
});
});

0 comments on commit 28907a7

Please sign in to comment.