HM-41. Доработан RouteService для работы с query (#13)

This commit is contained in:
Nikolay
2020-07-16 09:14:47 +03:00
committed by GitHub
parent 2be41edb2f
commit e1bc9e6dcd
4 changed files with 68 additions and 83 deletions

View File

@ -1,15 +0,0 @@
// ! TODO: Удалить, необходим для примера работы с компонентами
import Component from '../component';
class TestButton extends Component {
constructor () {
super('#test-button', document.body);
this.addEventListener(this.mainNode, 'click', (evt) => {
this.next('click', evt);
});
}
}
export default TestButton;

View File

@ -1,3 +0,0 @@
import TestButton from './TestButton';
export default TestButton;

View File

@ -1,5 +1,5 @@
import EmitService from './EmitService';
import {parse} from 'querystring';
import {parse, stringify} from 'querystring';
const ROUTE_CHANGE = 'routeChange';
@ -26,8 +26,10 @@ class RouteService extends EmitService {
this.generateNext();
}
goTo = (url) => {
this.history.pushState({}, '', url);
goTo = (url, query) => {
const stringQuery = stringify(query);
const urlWithQuery = url + (stringQuery ? `?${stringQuery}` : '');
this.history.pushState({}, '', urlWithQuery);
this.generateNext();
}