Links
HTML element <a> allows to navigate to a url. Library modifies this behavior to prevent a white flash. Request to server is made using Fetch API, and response body replaces the current document without a full page reload.
In some cases regular <a> behavior preserved:
- when
hrefattribute value has only a hash; - when
<a>has non-emptytargetattribute; - when
<a>has non-http(s)url as thehrefattribute value (tel:,mailto:etc.).
Methods from the list above can be used in markup. When you need to keep regular <a> behavior in JavaScript - call method Event#preventDefault inside your click event handler for an appropriate element.
Event flow
- A
<a>element triggers nativeclickevent in browser - Library triggers
ajaxify:fetchevent and starts AJAX request - When the AJAX request ends library dispatches
ajaxify:loadevent with the response object - If
ajaxify:loadwasn't prevented triggersajaxify:renderevent and updates content of the<body>element
Take a look at the Custom Events section to read about dispatched events in more details.