Skip to content

Commit 5b72430

Browse files
committed
feat(UrlMatcher): allow shorthand definitions
When defining parameter configurations, `{ param: "default" }` is now equivalent to `{ param: { value: "default" }}`.
1 parent 101012e commit 5b72430

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/urlMatcherFactory.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ function UrlMatcher(pattern, config) {
9595

9696
function paramConfig(param) {
9797
if (!config.params || !config.params[param]) return {};
98-
return config.params[param];
98+
var cfg = config.params[param];
99+
return isObject(cfg) ? cfg : { value: cfg };
99100
}
100101

101102
this.source = pattern;

test/urlMatcherFactorySpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ describe("urlMatcherFactory", function () {
310310
expect(m.exec('/users/2/bar')).toEqual({ id: 2, test: "bar" });
311311
expect(m.exec('/users/bar/2')).toBeNull();
312312
});
313+
314+
it("should allow shorthand definitions", function() {
315+
var m = new UrlMatcher('/foo/:foo', {
316+
params: { foo: "bar" }
317+
});
318+
expect(m.exec("/foo")).toEqual({ foo: "bar" });
319+
});
313320
});
314321
});
315322

0 commit comments

Comments
 (0)