Commit 816c4d23 by Daniel Lee

url: fix for boolean querystring parameters

Without this fix then the querystring looks like ?abool=true which causes
a mismatch with the angular routing. This results in a redirect and messes
up the browser history and back button.
parent 465e701b
......@@ -12,7 +12,11 @@ export function toUrlParams(a) {
let add = function(k, v) {
v = typeof v === 'function' ? v() : v === null ? '' : v === undefined ? '' : v;
s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v);
if (typeof v !== 'boolean') {
s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v);
} else {
s[s.length] = encodeURIComponent(k);
}
};
let buildParams = function(prefix, obj) {
......
......@@ -23,4 +23,10 @@ describe('ViewStore', () => {
expect(toJS(store.query.get('values'))).toMatchObject(['A', 'B']);
expect(store.currentUrl).toBe('/hello?values=A&values=B');
});
it('Query can contain boolean', () => {
store.updatePathAndQuery('/hello', { abool: true });
expect(toJS(store.query.get('abool'))).toBe(true);
expect(store.currentUrl).toBe('/hello?abool');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment