-
Notifications
You must be signed in to change notification settings - Fork 0
HTML5 PushState
As of version 0.7, PathJS officially supports the HTML5 History API via pushState. Before reading this page, please make sure you've read the wiki page about Getting Started. The HTML5 History API is only supported by some modern browsers.
- There is no support for root routes or default routes, as these don't make sense when the URI contains no special characters. Simply pass the full route around.
- There is no need to call the Path.listen() method, as you are no longer waiting for events - you will be manually calling them.
- To trigger an event, call the
Path.history.pushStatemethod, rather than thehistory.pushStatemethod.
You define the routes the same as usual, except you omit the Hashtag from your route:
Path.map("/html5/rocks").to(function(){
alert("Hello, World!");
});
Much like the regular HTML5 History API, to add a new history item to the global history object, you need to call the pushState method. When you want to use the PathJS Route Dispatcher, you need to call the PathJS pushState method.
Path.history.pushState(state, title, path);
The Path.history.pushState method is analogous to the standard history.pushState method, but wraps calls to the PathJS dispatcher. Using this method, you will
not need to modify the window.onpopstate method. You can access the history state information the same as if you had manually set the state via history.pushState.
Please keep in mind that the functionality provided by Path.history.pushState is only available in modern browsers that support the HTML5 History API.