Skip to content

Commit

Permalink
Fixing a bug in the getRoute method
Browse files Browse the repository at this point in the history
  • Loading branch information
Krasimir Tsonev committed Jan 9, 2021
1 parent 25dd66c commit c84fbd5
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.3.1

Fixing a bug in the `getRoute` method.

## 8.3.0

Adding `addBeforeHook`, `addAfterHook`, `addAlreadyHook`, `addLeaveHook` and `getRoute` methods.
Expand Down
4 changes: 2 additions & 2 deletions lib/navigo.amd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/navigo.amd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.amd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.amd.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/navigo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/navigo.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "navigo",
"version": "8.3.0",
"version": "8.3.1",
"description": "A simple vanilla JavaScript router",
"main": "lib/navigo.js",
"browser": "lib/navigo.min.js",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("Given the Navigo library", () => {
const router: NavigoRouter = new Navigo("/foo");
router.on(/^b/, handler);
expect(router.routes).toStrictEqual([
{ path: /^b/, handler, hooks: {}, name: "/^b/" },
{ path: /^b/, handler, hooks: {}, name: "^b" },
]);
});
it("should accept object with paths and handlers", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/getRoute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("Given the Navigo library", () => {
expect(r.routes).toHaveLength(3);
expect(r.getRoute("foo")).toStrictEqual(r.routes[0]);
expect(r.getRoute("xxx")).toStrictEqual(r.routes[1]);
expect(r.getRoute("/foo(.*)/")).toStrictEqual(r.routes[2]);
expect(r.getRoute("foo(.*)")).toStrictEqual(r.routes[2]);
expect(r.getRoute("nope")).toEqual(undefined);
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function Navigo(
): Route {
path = isString(path) ? clean(`${root}/${clean(path as string)}`) : path;
return {
name: name || String(path),
name: name || clean(String(path)),
path,
handler,
hooks: accumulateHooks(hooks),
Expand Down Expand Up @@ -335,8 +335,8 @@ export default function Navigo(
}
return () => {};
}
function getRoute(name): Route | undefined {
return routes.find((r) => r.name === name);
function getRoute(name: string): Route | undefined {
return routes.find((r) => r.name === clean(name));
}

this.root = root;
Expand Down

0 comments on commit c84fbd5

Please sign in to comment.