Follows this link with JavaScript and updates a fragment with the server response.
Following a link is considered navigation by default.
This will update the fragment <div class="content">
with the same element
fetched from /posts/5
:
<a href="/posts/5" up-follow up-target=".content">Read post</a>
If no [up-target]
attribute is set, the main target is updated.
You can configure Unpoly to follow all links on a page without requiring an [up-follow]
attribute.
See Handling all links and forms.
You can tell Unpoly to ignore clicks on an [up-follow]
link, causing the link to be non-interactive.
Use one of the following methods:
up:link:follow
event on the link elementup:click
event on the link elementTo force a full page load when a followable link is clicked:
[up-follow=false]
attribute on the link elementup:link:follow
event and call up.network.loadPage(event.renderOptions)
.You can set an [up-follow]
attribute on any non-interactive element to make it behave like a hyperlink:
<span up-follow up-href="/details">Read more</span>
See Acting like a hyperlink for details.
Links can update multiple fragments or append content to an existing element.
See Fragment placement for details.
You may omit the [up-follow]
attribute if the link has one of the following attributes:
[up-target]
[up-layer]
[up-transition]
[up-content]
[up-fragment]
[up-document]
Such a link will still be followed through Unpoly.
Whether this fragment update is considered navigation.
Setting this to false
will disable most defaults documented below,
causing Unpoly to render a fragment without side-effects like updating history
or scrolling.
The URL to fetch from the server.
See loading content from a URL.
To use a different URL when a link is followed through Unpoly (as opposed to a browser's full page load),
set an [up-href]
attribute.
Instead of making a server request, you may also render an existing string of HTML.
The target selector to update.
If omitted a main target will be rendered.
Specifies behavior if the target selector is missing from the current page or the server response.
If set to a CSS selector, Unpoly will attempt to replace that selector instead.
If set to true
Unpoly will attempt to replace a main target instead.
If set to false
Unpoly will immediately reject the render promise.
Controls which fragment to update when the [up-target]
selector yields multiple results.
When set to 'region'
Unpoly will prefer to update fragments in the
region of the origin element.
If set to 'first'
Unpoly will always update the first matching fragment.
Defaults to up.fragment.config.match
, which defaults to 'region'
.
The HTTP method to use for the request.
Common values are get
, post
, put
, patch
and delete
. The value is case insensitive.
The HTTP method may also be passed as an [data-method]
attribute.
By default, methods other than get
or post
will be converted into a post
request, and carry
their original method as a configurable _method
parameter.
A JSON object with additional parameters that should be sent as the request's query string or payload.
When making a GET
request to a URL with a query string, the given { params }
will be added
to the query parameters.
A JSON object with additional request headers.
Unpoly will by default send a number of custom request headers.
E.g. the X-Up-Target
header includes the target selector.
See up.protocol
for details.
The new inner HTML for the targeted fragment.
A string of HTML comprising only the new fragment's outer HTML.
With an [up-fragment]
attribute you can omit the [up-target]
attribute.
The target will be derived from the root element in the given HTML.
A string of HTML containing the targeted fragment.
See Extracting an element's outer HTML from a larger HTML string.
Whether the server response should be considered failed.
For failed responses Unpoly will use attributes prefixed with up-fail
, e.g. [up-fail-target]
.
See handling server errors for details.
By default any HTTP status code other than 2xx or 304 is considered an error code.
Set [up-fail=false]
to handle any response as successful, even with a 4xx or 5xx status code.
Whether the browser URL, window title and meta tags will be updated.
If set to true
, the history will always be updated, using the title and URL from
the server response, or from given [up-title]
and [up-location]
attributes.
If set to auto
history will be updated if the [up-target]
matches
a selector in up.fragment.config.autoHistoryTargets
. By default this contains all
main targets.
If set to false
, the history will remain unchanged.
See Updating history.
An explicit document title to set before rendering.
By default the title is extracted from the response's <title>
tag.
To prevent the title from being updated, set [up-title=false]
to explicitly
This attribute is only used when updating history.
An explicit URL to set before rendering.
By default Unpoly will use the link's [href]
or the final URL after the server redirected.
To prevent the URL from being updated, set [up-location=false]
.
This attribute is only used when updating history.
Whether to update meta tags in the <head>
.
By default Unpoly will extract meta tags from the response's <head>
.
To prevent meta tags from being updated, set [up-meta-tags=false]
.
This attribute is only used when updating history.
An explicit language code to set as the html[lang]
attribute.
By default Unpoly will extract the language from the response and update the html[lang]
attribute in the current page.
To prevent the attrribute from being changed, set [up-lang=false]
.
This attribute is only used when updating history.
The name of an transition to morph between the old and few fragment.
If you are prepending or appending content,
use the [up-animation]
attribute instead.
The name of an animation to reveal a new fragment when prepending or appending content.
If you are replacing content (the default), use the [up-transition]
attribute instead.
The duration of the transition or animation (in millisconds).
The timing function that accelerates the transition or animation.
See MDN documentation for a list of available timing functions.
Whether to read from and write to the cache.
With [up-cache=true]
Unpoly will try to re-use a cached response before connecting
to the network. To prevent display of stale content, cached responses are
reloaded once rendered. If no cached response exists,
Unpoly will make a request and cache the server response.
With [up-cache=auto]
Unpoly will use the cache only if up.network.config.autoCache
returns true
for the request. By default this only caches GET
requests.
With [up-cache=false]
Unpoly will always make a network request.
Whether to reload the targeted fragment after it was rendered from a cached response.
With [up-revalidate='auto']
Unpoly will revalidate if the up.fragment.config.autoRevalidate(response)
returns true
. By default this configuration will return true for
expired responses.
With [up-revalidate='true']
Unpoly will always revalidate cached content, regardless
of its age.
With [up-revalidate='false']
Unpoly will never revalidate cached content.
Whether existing cache entries will be expired with this request.
By default a non-GET request will expire the entire cache. You may also pass a URL pattern to only expire matching requests.
Also see up.request({ expireCache })
and up.network.config.expireCache
.
Whether existing cache entries will be evicted with this request.
You may also pass a URL pattern to only evict matching requests.
Also see up.request({ evictCache })
and up.network.config.evictCache
.
Whether to abort existing requests before rendering.
Whether this request may be aborted by other requests targeting the same fragments or layer.
See aborting requests for details.
Whether this request will load in the background.
Background requests deprioritized over foreground requests.
Background requests also won't emit up:network:late
events and won't trigger
the progress bar.
The number of milliseconds after which this request can cause
an up:network:late
event.
Defaults to up.network.config.badResponseTime
.
The number of milliseconds after which this request fails with a timeout.
Defaults to up.network.config.timeout
.
The layer in which to match and render the fragment.
See layer option for a list of allowed values.
To open the fragment in a new overlay, pass [up-layer=new]
.
In this case attributes for [up-layer=new]
may also be used.
Whether to close overlays obstructing the updated layer when the fragment is updated.
This is only relevant when updating a layer that is not the frontmost layer.
A JSON object that will be merged into the context of the current layer once the fragment is rendered.
How to scroll after the new fragment was rendered.
See Scrolling for a list of allowed values.
Whether to animate the scroll motion when prepending or appending content.
When to snap to the top when scrolling to an element near the top edge of the viewport's scroll buffer.
When to move a revealed element to the top when scrolling to an element.
How much space to leave to the closest viewport edge when scrolling to an element.
How many pixel lines of high element to reveal when scrolling to an element.
Whether to save scroll positions before updating the fragment.
Saved scroll positions can later be restored with [up-scroll=restore]
.
What to focus after the new fragment was rendered.
See Controlling focus for a list of allowed values.
Whether to save focus-related state before updating the fragment.
Saved scroll positions can later be restored with [up-focus=restore]
.
A message the user needs to confirm before fragments are updated.
The message will be shown as a native browser prompt.
If the user does not confirm the render promise will reject and no fragments will be updated.
Whether to give the link an .up-active
class and the targeted element an .up-loading
class
while loading content.
See navigation feedback.
A JavaScript snippet that is executed when the server responds with new HTML, but before the HTML is rendered.
The snippet runs in the following scope:
Expression | Value |
---|---|
this |
The link being followed |
event |
A preventable up:fragment:loaded event |
The snippet will also run for failed responses.
A JavaScript snippet that is executed when Unpoly has updated fragments.
The snippet runs in the following scope:
Expression | Value |
---|---|
this |
The link being followed |
result |
The up.RenderResult for the respective render pass |
The snippet will be called zero, one or two times:
[up-on-rendered]
is not called.[up-on-rendered]
is called with the result.[up-on-rendered]
is called again with the final result.Also see Running code after rendering.
A JavaScript snippet that is execvuted when no further DOM changes will be caused by this render pass.
In particular:
Expression | Value |
---|---|
this |
The link being followed |
result |
The up.RenderResult for the last render pass that updated a fragment |
If revalidation re-rendered the fragment, result
describes updates from the
second render pass. If no revalidation was performed, or if revalidation yielded an empty response,
it is the result from the initial render pass.
Also see Awaiting postprocessing.
A JavaScript snippet that is executed when the fragment could not be loaded due to a disconnect or timeout.
Expression | Value |
---|---|
this |
The link being followed |
error |
An up.Offline error |
A JavaScript snippet that is run when any error is thrown during the rendering process.
Expression | Value |
---|---|
this |
The link being followed |
error |
An Error object |
The callback is also called when the render pass fails due to network issues, or aborts.
Also see Handling errors.
Whether [up-keep]
elements will be preserved in the updated fragment.
Whether [up-hungry]
elements outside the updated fragment will also be updated.