Advertisement
Guest User

Untitled

a guest
May 31st, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. Disable history feature
  2.  
  3. ```html
  4. data-enable-history=“false"
  5. ```
  6.  
  7. Manually update the state in the URL hash
  8.  
  9. ```js
  10. var search = $('#search');
  11. search.on('state:change', function() {
  12. var attributes = search.coveo(Coveo.QueryStateModel).getAttributes();
  13. var queryString = encodeURIComponent(Coveo.HashUtils.encodeValues(attributes));
  14.  
  15. // Update the hash
  16. router.navigate('search?' + queryString); // window.location.hash = 'search?' + queryString
  17. });
  18. ```
  19.  
  20.  
  21. Manually parse the hash
  22. ```js
  23. var MyRouter = Backbone.Router.extend({
  24. routes: {
  25. "search/?:query": "search"
  26. },
  27.  
  28.  
  29. search: function(query) {
  30. var newState = this.parseState(query);
  31.  
  32. var search = $('#search');
  33. var currentState = search.coveo('state');
  34. search.coveo('state', _.defaults(newState, currentState.defaultAttributes));
  35. search.coveo('executeQuery'); // Not sure if needed everytime
  36. }
  37.  
  38. parseState: function() {
  39. var state = URI.parseQuery(decodeURIComponent(hash));
  40.  
  41. var parsedState = {};
  42. _.each(state, (value, key) => {
  43. parsedState[key] = Coveo.HashUtils.getValue(key, '#' + decodeURIComponent(hash));
  44. });
  45.  
  46. return parsedState;
  47. }
  48. });
  49. ```
  50.  
  51. Should be similar with `react-router` or `angular`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement