Skip to content

Commit

Permalink
fix(removeRoute): remove named wildcard routes (#137)
Browse files Browse the repository at this point in the history
* fix #136

* Update test/router.test.ts

---------

Co-authored-by: Pooya Parsa <[email protected]>
  • Loading branch information
sirenkovladd and pi0 authored Sep 19, 2024
1 parent 87f7125 commit 379cfb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/operations/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function _remove(
}

// Wildcard
if (segment === "**") {
if (segment.startsWith("**")) {
if (node.wildcard) {
_remove(node.wildcard, method, segments, index + 1);
if (_isEmptyNode(node.wildcard)) {
Expand Down
10 changes: 10 additions & 0 deletions test/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,14 @@ describe("Router remove", function () {
params: { _: "components/snackbars" },
});
});

it("remove named wildcard routes", function () {
const route = "/user/**:id";
const router = createRouter([route]);

removeRoute(router, "GET", route);

expect(findRoute(router, "GET", "/user/123")).toBeUndefined();
expect(findRoute(router, "GET", "/user/wildcard")).toBeUndefined();
});
});

0 comments on commit 379cfb6

Please sign in to comment.