Veil UI
Components

Back Button

A button that returns to the previous page with a fallback URL.

Installation

$ npx veil-ui@latest add back-button

Usage

import { BackButton } from "@/components/ui/back-button";

<BackButton fallbackHref="/dashboard" />;

Examples

Basic

Outline

API reference

PropTypeDefaultDescription
labelstring"Back"Visible and accessible label.
fallbackHrefstring—Navigated to when there is no history entry.
showIconbooleantrueShows the leading arrow icon.
onClick() => void—Overrides the default history navigation.

Accessibility

  • Renders a real button with an icon plus visible text.
  • The arrow icon is decorative and hidden from assistive technology.
  • Pair fallbackHref with a stable destination for deep links.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add back-button --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { ArrowLeft } from "lucide-vue-next";

import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";

import type { BackButtonProps } from "./types";

defineOptions({ inheritAttrs: false });

const props = withDefaults(defineProps<BackButtonProps>(), {
  label: "Back",
  showIcon: true,
  variant: "ghost",
  size: "sm",
});

function handleClick() {
  if (props.onClick) {
    props.onClick();
    return;
  }
  if (props.fallbackHref) {
    window.location.href = props.fallbackHref;
    return;
  }
  window.history.back();
}
</script>

<template>
  <Button
    data-slot="back-button"
    type="button"
    :variant="variant"
    :size="size"
    :class="cn('gap-1.5', props.class)"
    @click="handleClick"
    v-bind="$attrs"
  >
    <ArrowLeft v-if="showIcon" aria-hidden="true" />
    {{ label }}
  </Button>
</template>

On this page