Skip to content

Commit

Permalink
Fixing a bug with matchLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Krasimir Tsonev committed Feb 14, 2021
1 parent 1d2c12e commit bbf47a4
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 7 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.10

Fixing a bug with `matchLocation`.

## 8.8.9

Proper `url` of the Match object in case of custom `root`.
Expand Down
4 changes: 4 additions & 0 deletions lib/es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ export default function Navigo(appRoute, resolveOptions) {
}

function directMatchWithLocation(path, currentLocation, annotatePathWithRoot) {
if (currentLocation && typeof annotatePathWithRoot === "undefined" || annotatePathWithRoot) {
currentLocation = composePathWithRoot(currentLocation);
}

var context = {
instance: self,
to: currentLocation,
Expand Down
4 changes: 4 additions & 0 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: 4 additions & 0 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.8.9",
"version": "8.8.10",
"description": "A simple vanilla JavaScript router",
"main": "lib/navigo.js",
"browser": "lib/navigo.min.js",
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,17 @@ describe("Given the Navigo library", () => {
});
});
});
describe("when using matchLocation and we have a custom root", () => {
it("should properly match the path", () => {
const r: NavigoRouter = new Navigo("/app");

expect(r.matchLocation("posts/edit/:id", "posts/edit/xxx")).toStrictEqual(
expect.objectContaining({
data: {
id: "xxx",
},
})
);
});
});
});
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ export default function Navigo(
currentLocation?: string,
annotatePathWithRoot?: boolean
): false | Match {
if (
(currentLocation && typeof annotatePathWithRoot === "undefined") ||
annotatePathWithRoot
) {
currentLocation = composePathWithRoot(currentLocation);
}
const context: QContext = {
instance: self,
to: currentLocation,
Expand Down

0 comments on commit bbf47a4

Please sign in to comment.