Files
old-kivi/web/lib/router.js
Edin Dazdarevic 562bbc638f Router WIP
2017-04-08 05:11:45 +02:00

19 lines
719 B
JavaScript

export default class Router {
constructor(comp) {
this.component = comp;
}
update () {
// Take the state from the component and update the URL
const {listingId, sort, minPrice, maxPrice, minSize, maxSize, filters: {rooms, category}} = this.component.state;
const bounds = this.component.map.getBounds().toUrlValue();
const params = [];
params.push(`listingId=${listingId}`);
params.push(`sort=${sort}`);
params.push(`bounds=${bounds}`);
params.push(`rooms=${Object.keys(rooms).filter(v => rooms[v]).join(",")}`);
params.push(`category=${Object.keys(category).filter(v => category[v]).join(",")}`);
window.history.pushState({}, '', `/?${params.join("&")}`);
}
}