Skip to content

Commit

Permalink
Second try fixing #57 (3.3.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krasimir Tsonev committed Nov 7, 2016
1 parent 6c7b1b1 commit 1bd38e9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.3.3

* Another try fixing [#57](https://github.com/krasimir/navigo/issues/57) - now if we have `noHash=false` the hash part of the URL is removed and we are no longer considering it while comparing the last resolved URL.

## 3.3.2

* Fixing [#57](https://github.com/krasimir/navigo/issues/57) - making sure that we keep the last resolved url when we have the `notFound` handler resolves.
Expand Down
7 changes: 5 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

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.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": "3.3.2",
"version": "3.3.3",
"description": "A simple vanilla JavaScript router with a fallback for older browsers",
"main": "lib/navigo.js",
"jsnext:main": "src/index.js",
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ function isHashChangeAPIAvailable() {
);
}

function extractGETParameters(url) {
function extractGETParameters(url, useHash) {
var [ onlyURL, ...query ] = url.split(/\?(.*)?$/);

if (!useHash) {
onlyURL = onlyURL.split('#')[0];
}
return { onlyURL, GETParameters: query.join('') };
}

Expand Down Expand Up @@ -184,7 +187,7 @@ Navigo.prototype = {
if (this._useHash) {
url = url.replace(/^\/#/, '/');
}
let { onlyURL, GETParameters } = extractGETParameters(url);
let { onlyURL, GETParameters } = extractGETParameters(url, this._useHash);

if (
this._paused ||
Expand Down
4 changes: 3 additions & 1 deletion test/spec/InBrowser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ describe('Given the Navigo library on the page', function () {

window.location.hash = 'tab1';
router.resolve();
window.location.hash = 'tab2';
router.resolve();

expect(notFoundHandler).to.be.calledOnce;
expect(defaultHandler).to.not.be.calledOnce;
expect(handler).to.not.be.calledOnce;
expect(handler).to.not.be.called;
});
});
});

0 comments on commit 1bd38e9

Please sign in to comment.