Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Disable history feature
- ```html
- data-enable-history=“false"
- ```
- Manually update the state in the URL hash
- ```js
- var search = $('#search');
- search.on('state:change', function() {
- var attributes = search.coveo(Coveo.QueryStateModel).getAttributes();
- var queryString = encodeURIComponent(Coveo.HashUtils.encodeValues(attributes));
- // Update the hash
- router.navigate('search?' + queryString); // window.location.hash = 'search?' + queryString
- });
- ```
- Manually parse the hash
- ```js
- var MyRouter = Backbone.Router.extend({
- routes: {
- "search/?:query": "search"
- },
- search: function(query) {
- var newState = this.parseState(query);
- var search = $('#search');
- var currentState = search.coveo('state');
- search.coveo('state', _.defaults(newState, currentState.defaultAttributes));
- search.coveo('executeQuery'); // Not sure if needed everytime
- }
- parseState: function() {
- var state = URI.parseQuery(decodeURIComponent(hash));
- var parsedState = {};
- _.each(state, (value, key) => {
- parsedState[key] = Coveo.HashUtils.getValue(key, '#' + decodeURIComponent(hash));
- });
- return parsedState;
- }
- });
- ```
- Should be similar with `react-router` or `angular`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement