ember-link
It's like {{link-to}}
, but renderless!
Renderless / Container / Provider Components are components that don't emit any DOM, but only yield state and actions to nested components.
The idea for this component traces back to this EmberMap session: Using Functional CSS with Ember.
Installation
ember install ember-link
👉 This is an Ember Octane addon. For a version that is compatible with older versions of Ember check out the
0.x
series.
Usage
Arguments
@route
Required.
The target route name.
Example
{{link-to}}
equivalent
@models
Optional. Mutually exclusive with @model
.
An array of models / dynamic segments.
Example
{{link-to}}
equivalent
@model
Optional. Mutually exclusive with @models
.
Shorthand for providing a single model / dynamic segment. The following two invocations are equivalent:
@query
Optional.
Query Params object.
Example
{{link-to}}
equivalent
@preventDefault
Optional. Default: true
If enabled, the transitionTo
and
replaceWith
actions will try to call
event.preventDefault()
on the first argument, if it is an
event. This is an anti-foot-gun to make <Link>
just work™️ with <a>
and
<button>
, which would otherwise trigger a native browser navigation / form
submission.
Yielded Parameters
href
string
The URL for this link that you can pass to an <a>
tag as the href
attribute.
isActive
boolean
Whether this route is currently active, including potentially supplied models and query params.
In the following example, only one link will be is-active
at any time.
isActiveWithoutQueryParams
boolean
Whether this route is currently active, including potentially supplied models, but ignoring query params.
In the following example, the first two links will be is-active
simultaneously.
isActiveWithoutModels
boolean
Whether this route is currently active, but ignoring models and query params.
In the following example, both links will be is-active
simultaneously.
transitionTo()
(event?: Event) => Transition
Transition into the target route.
If @preventDefault
is enabled, also calls event.preventDefault()
.
replaceWith()
(event?: Event) => Transition
Transition into the target route while replacing the current URL, if possible.
If @preventDefault
is enabled, also calls event.preventDefault()
.