API REFERENCE · NAVIGATION
<dj-back-button>
A Back button that follows the app's navigation history.
It is built on <dj-button>, so keyboard use, focus, and button semantics come from there. Install @dojo-ng/history once at startup; the button finds it through HistoryController.
npm install @dojo-ng/nav-history
import "@dojo-ng/nav-history";
Modes
history(the default) does what the browser's Back button does, and is disabled when there is nowhere to go back to. With no history installed it callswindow.history.back()and is never disabled.upgoes to the parent of the current page instead, by dispatchingdj-navigate. The parent is the second-to-last entry of the location'strailwhen it has one (a trackeddj-treesupplies it), otherwise the current path with its last segment removed. At the top level, a single-segment path or a trail of one, there is no parent, and the button behaves exactly as inhistorymode.
Label
- In
upmode with a parent, the label is "Back to {title}". The title is the trail entry's label, otherwise whatresolveTitle(parentPath)returns. With no title, or inhistorymode, the label is "Back". Setlabelto replace the computed text. - The label is recomputed on every location change, including when a trail arrives late, so it needs no timer.
- The accessible name always equals the visible label. With
icon-only, only the arrow shows, the label becomes the accessible name, and a tooltip shows it on hover and focus.
Taking over
dj-backfires first and can be canceled. CallpreventDefault()to do something else (confirm unsaved changes, close a panel); the button then does nothing further.
Properties
| Property | Attribute | Type | Default |
|---|---|---|---|
modehistory calls Back. up goes to the parent page. |
mode reflected |
"history""up" |
"history" |
labelReplaces the computed label. |
label |
string |
None |
iconOnlyShow only the arrow. The label is still the accessible name, and a tooltip shows it. |
icon-only reflected |
boolean |
false |
resolveTitleLooks up the title of the parent page in up mode when the trail has none. JS only. |
Property only | (path: string) => string | undefined |
None |
Events
| Event | Description |
|---|---|
dj-back | cancelable, detail { mode, target } |
dj-navigate | detail { path, label?, trail? } |
CSS parts
Style these with dj-back-button::part(name).
| Part | Description |
|---|---|
button | the composed <dj-button> |
Methods
focus(options: FocusOptions)blur()