Which links are handled
What Pagefold takes over, what it leaves to the browser, and how to opt a link out.
By default Pagefold handles every a[href] on the page (change it with linkSelector). It leaves a link to the browser when:
- it points to another origin;
- it has
target="_blank"or adownloadattribute; - it is clicked with a modifier key (Cmd, Ctrl, Shift, Alt) or any button other than the left one. The hook
link:newtabfires for modifier clicks; - it, or an ancestor, has the attribute
data-no-pagefold; - your
ignoreVisit(url, { el, event })option returnstrue.
<a href="/legacy-page" data-no-pagefold>Normal page load</a>
The decision, step by step
Every click on a link goes through these questions, in this order. The first “yes” hands the link back to the browser. If every answer is “no”, Pagefold takes over.
- Is it on another origin? Another domain, subdomain or port.Yes → browser
- Does it have target="_blank" or download?Yes → browser
- Does it, or an ancestor, have data-no-pagefold? Or does your ignoreVisit option return true?Yes → browser
- Was a modifier key held (Cmd, Ctrl, Shift, Alt)? The hook link:newtab fires first.Yes → browser
- Was it any button other than the left one?Yes → browser
- Pagefold handles it: link:click fires, then the visit starts.
Yes: The browser handles it, as if Pagefold was not there.
Links to the current page
| Link | What happens |
|---|---|
#section on the same page | Scrolls to the anchor. Hook: link:anchor |
| The page you are already on | Scrolls to the top (linkToSelf: 'scroll') or reloads it through Pagefold (linkToSelf: 'navigate'). Hook: link:self |
Per-link attributes
<!-- Use the animation named "slide" -->
<a href="/about" data-pagefold-animation="slide">About</a>
<!-- Replace the history entry instead of adding one -->
<a href="/step-2" data-pagefold-history="replace">Next</a>
The attribute can be on the link or on any ancestor.
Keeping elements across pages
Elements with data-pagefold-persist and a name survive a visit. Put the same element, with the same name, in every page.
<audio data-pagefold-persist="player" src="song.mp3" controls></audio>
Navigating from code
pagefold.navigate('/about')
pagefold.navigate('/about', { animation: 'slide', history: 'replace' })
See The Pagefold instance for all the options.