Skip to content

Commit 849bbb6

Browse files
committed
Merge pull request #57 from STRML/master
Upgrade url-pattern and support optional patterns.
2 parents c8ddaed + c37e52c commit 849bbb6

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/matchRoutes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function matchRoutes(routes, path) {
2828
}
2929

3030
if (current.path) {
31-
current.pattern = current.pattern || pattern(current.path);
31+
current.pattern = current.pattern || pattern.newPattern(current.path);
3232
if (!page) {
3333
match = current.pattern.match(path);
3434
if (match) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Declarative router component for React",
55
"main": "index.js",
66
"dependencies": {
7-
"url-pattern": "~0.4.0",
7+
"url-pattern": "~0.6.0",
88
"envify": "^1.2.1",
99
"urllite": "~0.4.0"
1010
},

tests/matchRoutes.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ describe('matchRoutes', function() {
88
}
99

1010
var routes = [
11-
{path: '/', handler: handler({name: 'root'})},
11+
{path: '(/)', handler: handler({name: 'root'})},
1212
{path: '/cat/:id', handler: handler({name: 'cat'})},
1313
{path: '/mod/*', handler: handler({name: 'mod'})},
1414
{path: null, handler: handler({name: 'notfound'})}
1515
];
1616

17+
it('matches ""', function() {
18+
var match = matchRoutes(routes, '');
19+
assert(match.route);
20+
assert.strictEqual(match.route.handler.name, 'root');
21+
assert.deepEqual(match.match, {});
22+
assert.strictEqual(match.path, '');
23+
assert.strictEqual(match.matchedPath, '');
24+
assert.strictEqual(match.unmatchedPath, null);
25+
});
26+
1727
it('matches /', function() {
1828
var match = matchRoutes(routes, '/');
1929
assert(match.route);

0 commit comments

Comments
 (0)