The Crossroads router and API is provided for those developers who are building applications on top of Commerce Store Accelerator and need to exercise more control over the response to URL change requests. Out of the box, however, Commerce Store Accelerator only goes through the process of creating a Crossroads router instance and notifying it of the URL change. It does not introduce any custom logic using the Crossroads API and its pattern matching techniques. Instead, Commerce Store Accelerator simply triggers a re-loading of the view model for the newly requested URL. When the view model for the page is loaded, any changes in the model data is detected by Knockout. Through the use of Knockout bindings, the areas of the page that are associated with the changed data are subsequently updated.

  // When the state changes
  window.addEventListener('changestate', function (e) {
    // Notify the router of the URL change
    router.parse(e.detail.URL);

    // Notify the view model of the URL change
    viewModel.load(e.detail.URL);
  });

See https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history for details on the History API.


Copyright © 1997, 2016 Oracle and/or its affiliates. All rights reserved. Legal Notices