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
href
attribute value has only a hash; - when
<a>
has non-emptytarget
attribute; - when
<a>
has non-http(s)
url as thehref
attribute 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 nativeclick
event in browser - Library triggers
ajaxify:fetch
event and starts AJAX request - When the AJAX request ends library dispatches
ajaxify:load
event with the response object - If
ajaxify:load
wasn't prevented triggersajaxify:render
event and updates content of the<body>
element
Take a look at the Custom Events section to read about dispatched events in more details.