Pagefold

The Pagefold instance

The methods and properties of the object you get from new Pagefold().

Methods

Visit a URL from code. Returns a promise that resolves when the visit is over.

await pagefold.navigate('/pricing')

await pagefold.navigate('/search', {
  method: 'POST',
  body: new URLSearchParams({ q: 'cats' }),
  cache: false,
})
OptionWhat it does
animatefalse swaps the content without animating
animationAn animation name
history'push' or 'replace'
cachefalse skips the cache for this visit, or { read, write } for each
metaYour own data, available as visit.meta
method, body, headers, timeout, signalPassed to the request

URLs that Pagefold would not handle (another origin, for example) load normally.

use(plugin), unuse(plugin or name), findPlugin(plugin or name)

Add, remove and look up plugins after startup.

fetchPage(url, options?, visit?)

Fetch a page and store it in the cache, without showing it. Pass your own visit to keep the request separate from the current navigation. This is how the Preload plugin works.

replaceContent(visit?)

Replace the containers from visit.to.document. It returns whether all containers were replaced.

Others

MethodWhat it does
getAnchorElement(hash)The element a hash points to
getCurrentUrl()Path and query of the address bar
resolveUrl(url)Apply the resolveUrl option
isSameResolvedUrl(a, b)Do two URLs resolve to the same page
shouldIgnoreVisit(href, { el, event })Would Pagefold leave this to the browser
createVisit({ to, ... })Build a visit object
mount(selector, setup)Run setup(el) for each matching element now and after each visit, and its cleanup when the element leaves. Returns a function that stops it. See Components
enable()Start handling links. Runs on creation
destroy()Stop handling links, unmount plugins, clean up components and remove all hook handlers

Properties

PropertyWhat it is
versionThe library version
optionsThe options in use
hooksThe hook registry: on, before, once, replace, off, call, callSync, create, exists, names, clear
cacheThe page cache: has, get, set, update, delete, clear, prune, size, all (a copy, as a Map)
classesThe state class manager: add, remove, clear
visitThe current or last visit
locationThe page currently shown
pluginsThe installed plugins
logA function plugins use for debug messages. Does nothing until the Debug plugin replaces it

Stopping Pagefold

await pagefold.destroy()

Links go back to normal and the pagefold-enabled class is removed.