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 {
|
parseRootSegment(): UrlSegment {
|
||||||
if (this.remaining === '' || this.remaining === '/') {
|
if (this.remaining.startsWith('/')) {
|
||||||
|
this.capture('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.remaining === '' || this.remaining.startsWith('?')) {
|
||||||
return new UrlSegment([], {});
|
return new UrlSegment([], {});
|
||||||
} else {
|
} else {
|
||||||
return new UrlSegment([], this.parseSegmentChildren());
|
return new UrlSegment([], this.parseSegmentChildren());
|
||||||
|
@ -91,6 +91,13 @@ describe('url serializer', () => {
|
|||||||
expect(url.serialize(tree)).toEqual('/one;a=true');
|
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', () => {
|
it('should parse query params', () => {
|
||||||
const tree = url.parse('/one?a=1&b=2');
|
const tree = url.parse('/one?a=1&b=2');
|
||||||
expect(tree.queryParams).toEqual({a: '1', b: '2'});
|
expect(tree.queryParams).toEqual({a: '1', b: '2'});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user