Dojo NG is being built in the open, one section at a time — follow along on Heptapod.

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.

Try it in the playground

@dojo-ng/nav-history · v0.2.0 · The same package also registers <dj-forward-button>.

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 calls window.history.back() and is never disabled.
  • up goes to the parent of the current page instead, by dispatching dj-navigate. The parent is the second-to-last entry of the location's trail when it has one (a tracked dj-tree supplies 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 in history mode.

Label

  • In up mode with a parent, the label is "Back to {title}". The title is the trail entry's label, otherwise what resolveTitle(parentPath) returns. With no title, or in history mode, the label is "Back". Set label to 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-back fires first and can be canceled. Call preventDefault() to do something else (confirm unsaved changes, close a panel); the button then does nothing further.

Properties

PropertyAttributeTypeDefault
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

EventDescription
dj-backcancelable, detail { mode, target }
dj-navigatedetail { path, label?, trail? }

CSS parts

Style these with dj-back-button::part(name).

PartDescription
buttonthe composed <dj-button>

Methods

focus(options: FocusOptions)blur()