Skip to content

Commit 672c669

Browse files
Krasimir Tsonevemflores
Krasimir Tsonev
authored andcommitted
Updating the last resolved route when a default handler is called krasimir#41
1 parent 8452e94 commit 672c669

File tree

7 files changed

+34
-9
lines changed

7 files changed

+34
-9
lines changed

lib/navigo.js

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/navigo.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/navigo.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/navigo.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "navigo",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "A simple vanilla JavaScript router with a fallback for older browsers",
55
"main": "lib/navigo.js",
66
"jsnext:main": "src/index.js",

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Navigo.prototype = {
161161
handler(m.params);
162162
return m;
163163
} else if (this._defaultHandler && (url === '' || url === '/')) {
164+
this._lastRouteResolved = url;
164165
this._defaultHandler();
165166
return true;
166167
} else if (this._notFoundHandler) {

test/Navigo.spec.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ describe('Given an instance of Navigo', function () {
110110
expect(action).to.be.equal('save');
111111
done();
112112
};
113+
113114
router.on(/users\/(\d+)\/(\w+)\/?/, handler);
114115
router.resolve('site.com/app/users/42/save');
115116
});
@@ -118,6 +119,7 @@ describe('Given an instance of Navigo', function () {
118119
describe('and when we use the destroy method', function () {
119120
it('should not be able to resolve a route', function () {
120121
var handler = sinon.spy();
122+
121123
router.on('/users', handler);
122124
router.resolve('site.com/app/users');
123125
router.destroy();
@@ -245,7 +247,7 @@ describe('Given an instance of Navigo', function () {
245247

246248
expect(handler)
247249
.to.be.calledOnce
248-
.and.to.be.calledWith({ productId: '42' })
250+
.and.to.be.calledWith({ productId: '42' });
249251
});
250252
});
251253
});
@@ -271,4 +273,25 @@ describe('Given an instance of Navigo', function () {
271273
});
272274
});
273275

276+
describe('Given the issue #41 case', function () {
277+
it('should resolve routes properly', function () {
278+
var taskRoute = sinon.spy();
279+
var defaultRoute = sinon.spy();
280+
281+
router = new Navigo('http://site.com/', true);
282+
router.on('/task/:taskId/', taskRoute);
283+
router.on(defaultRoute);
284+
285+
router.resolve('/task/frontend-1');
286+
router.resolve('/');
287+
router.resolve('/task/frontend-1');
288+
289+
expect(defaultRoute).to.be.calledOnce;
290+
expect(taskRoute).to.be.calledTwice;
291+
expect(taskRoute.firstCall).to.be.calledWith({ taskId: 'frontend-1' });
292+
expect(taskRoute.secondCall).to.be.calledWith({ taskId: 'frontend-1' });
293+
294+
});
295+
});
296+
274297
});

0 commit comments

Comments
 (0)