Components
Back Button
A button that returns to the previous page with a fallback URL.
Installation
$ npx veil-ui@latest add back-buttonUsage
import { BackButton } from "@/components/ui/back-button";
<BackButton fallbackHref="/dashboard" />;Examples
Basic
Outline
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | "Back" | Visible and accessible label. |
| fallbackHref | string | — | Navigated to when there is no history entry. |
| showIcon | boolean | true | Shows 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
fallbackHrefwith 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>