fix(router): handle empty path with query params

This commit is contained in:
vsavkin 2016-06-25 12:07:47 -07:00
parent 90295e3252
commit 3f44377f2f
2 changed files with 12 additions and 1 deletions

View File

@ -277,7 +277,11 @@ class UrlParser {
}
parseRootSegment(): UrlSegment {
if (this.remaining === '' || this.remaining === '/') {
if (this.remaining.startsWith('/')) {
this.capture('/');
}
if (this.remaining === '' || this.remaining.startsWith('?')) {
return new UrlSegment([], {});
} else {
return new UrlSegment([], this.parseSegmentChildren());

View File

@ -91,6 +91,13 @@ describe('url serializer', () => {
expect(url.serialize(tree)).toEqual('/one;a=true');
});
it('should parse query params (root)', () => {
const tree = url.parse('/?a=1&b=2');
expect(tree.root.children).toEqual({});
expect(tree.queryParams).toEqual({a: '1', b: '2'});
expect(url.serialize(tree)).toEqual('/?a=1&b=2');
});
it('should parse query params', () => {
const tree = url.parse('/one?a=1&b=2');
expect(tree.queryParams).toEqual({a: '1', b: '2'});