# Route Tabs

> A row of links between the pages of one section.

Page: https://uicontext.com/docs/components/route-tabs

Group: Navigation.

## When to use

A row of links between the pages of one section. Use [Tabs](https://uicontext.com/docs/components/tabs.md) instead when the panels change without a new address.

## Usage

```ts
import { RouteNav } from "./ui/uicontext/components/RouteNav.ts"

export const SettingsNav = <M>(h: Html.H<M>, current: string) =>
	RouteNav(h, {
		label: "Settings",
		current,
		items: [
			{ id: "general", label: "General", href: "/settings" },
			{ id: "members", label: "Members", href: "/settings/members" },
			{ id: "billing", label: "Billing", href: "/settings/billing" },
		],
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### Settings sections

The example the page opens with: Route Tabs in “Settings sections”.

```ts title="src/demo.ts" source="www/src/examples/route-tabs/demo.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { RouteNav } from "./ui/uicontext/components/RouteNav.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	bar: { inlineSize: "min(100%, 40rem)", paddingBlockEnd: 8, borderBlockEndWidth: 1, borderBlockEndStyle: "solid", borderBlockEndColor: color.line },
})

// real links: the app's router follows them, and the current page is marked for screen readers
export const WorkspaceSettingsNav = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.bar)).children(
		RouteNav(h, {
			label: "Workspace settings",
			current: "members",
			items: [
				{ id: "general", label: "General", href: "#general" },
				{ id: "members", label: "Members", href: "#members" },
				{ id: "billing", label: "Billing", href: "#billing" },
				{ id: "connections", label: "Connections", href: "#connections" },
				{ id: "security", label: "Security", href: "#security" },
				{ id: "audit", label: "Audit log", href: "#audit" },
			],
		}),
	)
```

### Narrower than its links

The row scrolls sideways instead of wrapping, and the current page scrolls into view.

```ts title="src/narrow.ts" source="www/src/examples/route-tabs/narrow.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { RouteNav } from "./ui/uicontext/components/RouteNav.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ frame: { inlineSize: "min(100%, 18rem)" } })

export const ProjectNav = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.frame)).children(
		RouteNav(h, {
			label: "Project",
			current: "updates",
			items: [
				{ id: "overview", label: "Overview", href: "#overview", glyph: "◎" },
				{ id: "issues", label: "Issues", href: "#issues", glyph: "◇" },
				{ id: "cycles", label: "Cycles", href: "#cycles", glyph: "↻" },
				{ id: "docs", label: "Documents", href: "#docs", glyph: "▤" },
				{ id: "updates", label: "Updates", href: "#updates", glyph: "✎" },
			],
		}),
	)
```

## API reference

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `label` (required) | `string` | The landmark's accessible name: "Settings". |
| `items` (required) | `RouteNavItem[]` | The links, each with an id, a label, an href and an optional glyph. |
| `current` | `string` | The id of the link to the page shown now, marked as the current page. |
| `style` | `Style` | StyleX styles for the row. |
| `linkStyle` | `Style` | Applied to every anchor after its default styles. |
| `currentStyle` | `Style` | Applied last to the current anchor. |
| `glyphStyle` | `Style` | StyleX styles for each link's glyph. |

## Keyboard and accessibility

- A `nav` landmark named by its `label`, holding real links; the current page is `aria-current="page"`.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/route-tabs
```

With npm: `npx shadcn@latest add checkfu/uicontext/route-tabs`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/route-tabs`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/route-tabs`.

It writes these files:

- `src/ui/uicontext/components/RouteNav.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/RouteNav.ts](https://github.com/checkfu/uicontext/blob/main/src/RouteNav.ts)

## Related

- [App Shell](https://uicontext.com/docs/components/app-shell.md) (`app-shell`): The frame of an app: a sidebar, the page and an optional side panel, on any screen size.
- [Tab Strip](https://uicontext.com/docs/components/tab-strip.md) (`tab-strip`): Document tabs over the page to open, close and drag to reorder.
- [Sidebar](https://uicontext.com/docs/components/sidebar.md) (`sidebar`): A navigation tree of workspaces, teams and pages.
- [Tree View](https://uicontext.com/docs/components/tree-view.md) (`tree-view`): Nested rows you open and close, such as files and folders. Children can load when opened.
- [Page Header](https://uicontext.com/docs/components/page-header.md) (`page-header`): A page's title, description, breadcrumb and actions.
- [Tabs](https://uicontext.com/docs/components/tabs.md) (`tabs`): Switch between panels, or between views of the same data.
