Skip to content

Commit 9b7cd73

Browse files
authored
Merge pull request #2 from remix/marco/add_match_functionality
Add match functionality
2 parents f73189c + 133d766 commit 9b7cd73

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ampersand-history.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Events = require('ampersand-events');
22
var extend = require('lodash/assign');
33
var bind = require('lodash/bind');
4+
var compact = require('lodash/compact');
45

56

67
// Handles cross-browser history management, based on either
@@ -232,6 +233,15 @@ extend(History.prototype, Events, {
232233
if (options.trigger) return this.loadUrl(fragment);
233234
},
234235

236+
match(fragment) {
237+
const handler = this.handlers.find(function (handler) {
238+
if (handler.route.test(fragment)) {
239+
return true;
240+
}
241+
});
242+
return compact(handler.route.exec(fragment));
243+
},
244+
235245
// Update the hash location, either replacing the current entry, or adding
236246
// a new one to the browser history.
237247
_updateHash: function (location, fragment, replace) {

ampersand-router.js

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ extend(Router.prototype, Events, {
6969
return this;
7070
},
7171

72+
// Match a URL fragment with the routes, returning an array of results
73+
// for the route. Return will include all the variables in the route.
74+
match: function(fragment) {
75+
return this.history.match(fragment);
76+
},
77+
7278
// Reload the current route as if it was navigated to from somewhere
7379
// else
7480
reload: function () {

0 commit comments

Comments
 (0)