Skip to content

Commit

Permalink
Proper of the Match object in case of custom
Browse files Browse the repository at this point in the history
  • Loading branch information
Krasimir Tsonev committed Feb 10, 2021
1 parent 4484689 commit 1d2c12e
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.8.9

Proper `url` of the Match object in case of custom `root`.

## 8.8.8

Fixing a bug with `directMatchWithLocation`. It wasn't aware for the `root`.
Expand Down
2 changes: 1 addition & 1 deletion lib/es/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function matchRoute(context, route) {
if (match) {
var data = isString(route.path) ? regExpResultToParams(match, paramNames) : match.groups ? match.groups : match.slice(1);
return {
url: current,
url: clean(current.replace(new RegExp("^" + context.instance.root), "")),
queryString: GETParams,
hashString: extractHashFromURL(context.to),
route: route,
Expand Down
2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion 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.8.8",
"version": "8.8.9",
"description": "A simple vanilla JavaScript router",
"main": "lib/navigo.js",
"browser": "lib/navigo.min.js",
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,28 @@ describe("Given the Navigo library", () => {
expect(r.current).toHaveLength(1);
});
});
describe("when we have a custom root and we have a match", () => {
it("should not include the root into the Match's url prop", () => {
const r: NavigoRouter = new Navigo("/app");
const h = jest.fn();

r.on("/login", h);
r.navigate("login");

expect(h).toBeCalledTimes(1);
expect(h).toBeCalledWith({
url: "login",
data: null,
params: null,
queryString: "",
hashString: "",
route: {
handler: expect.any(Function),
hooks: {},
name: "app/login",
path: "app/login",
},
});
});
});
});
2 changes: 1 addition & 1 deletion src/__tests__/navigate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe("Given the Navigo library", () => {
expect(location.pathname).toBe("/app/login");
expect(r.current).toStrictEqual([
expect.objectContaining({
url: "app/login",
url: "login",
}),
]);
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function matchRoute(context: QContext, route: Route): false | Match {
? match.groups
: match.slice(1);
return {
url: current,
url: clean(current.replace(new RegExp(`^${context.instance.root}`), "")),
queryString: GETParams,
hashString: extractHashFromURL(context.to),
route: route,
Expand Down

0 comments on commit 1d2c12e

Please sign in to comment.