fix(router): handle empty path with query params
This commit is contained in:
parent
90295e3252
commit
3f44377f2f
|
@ -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());
|
||||
|
|
|
@ -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'});
|
||||
|
|
Loading…
Reference in New Issue