Anchor

Navigate between sections on the current page or related routes.

Anchor

Default

Use a hash href for a heading on the current page, or pass a relative, root-relative, or absolute URL to navigate to another route. Anchor renders semantic links, so route items keep standard browser behaviors such as opening in a new tab and copying the destination.

Anchor has no router dependency. Provide a compatible router locally or through global Anchor configuration when the item tree contains same-origin page paths. Anchor classifies every href automatically: ordinary route clicks are delegated, while modified clicks remain native links and can open in a new tab.

Hierarchy

Use children recursively for any depth. A parent with href remains a normal target; omit href when it is only a grouping label. Set collapsible: true to let that item hide its descendants, and use defaultCollapsed for its initial state. If the active anchor is hidden in a collapsed branch, its ancestors open so the current location remains visible.

The active marker uses a built-in inline location SVG, so the default does not depend on an icon collection. Set anchor: { activeIcon: 'collection:name' } in SConfigProvider or the library install options to use a global icon. The active-icon slot has the highest priority and receives the active item and href.

Secondary link

Each item uses a stable href that points to a real page ID. The default heading strategy activates a heading after it crosses active-offset + bounds. Without active-offset, the line uses offset; target-offset independently controls where a click scrolls. visible-section instead compares how much of each heading-to-next-heading section occupies the viewport below offset.

Horizontal

Mixed route and anchor navigation

Provide router when one outline combines route-level chapters with headings inside each chapter; no mode switch is required. Anchor infers behavior per item. A bare #hash scrolls within the current document, another same-origin pathname uses the router, and a pathname plus hash uses the router only when its document differs. The previous/next sequence is flattened across groups and includes full routes without hashes by default; set boundary: true to include a cross-document hash such as an API endpoint, or false to exclude a route. Scrolling forward across the bottom edge opens the next entry at its start; scrolling backward across the top edge opens the previous entry at its end.

The router and page scroll owner control route-entry scrolling. Keep route changes instantaneous rather than relying on a global smooth-scroll rule, which can animate the new page backward from the previous page’s scroll position. Hash-link clicks still use Anchor’s scroll-behavior setting, which defaults to smooth.

The documentation outline uses active-strategy="visible-section" so its highlighted hash follows the section occupying most of the readable page area. The library default remains heading for existing applications. Set active-strategy on one Anchor, or set anchor: { activeStrategy: 'visible-section', activeOffset: 160 } in SConfigProvider or the installation options for a shared default. An explicit component prop takes precedence; activeOffset only changes the heading strategy.

Adjacent-route prefetching is opt-in and disabled by default. Set route-prefetch locally, or anchor: { routePrefetch: true } globally, and provide a router.prefetch(href) adapter that loads the matching lazy route module without navigating. Anchor schedules only the previous and next eligible routes while idle, deduplicates them by route path, and never mounts their components or loads their page data itself.

When entering the next route through a boundary, the outline waits for its scroll position to settle at the new page start before selecting a page hash. The first heading stays active through the beginning of the chapter; later headings take over as they enter the reading area.

Pass a Vue Router-compatible object locally through router. For example, use vue-smart-router or another compatible router to handle navigation.

<script setup lang="ts">
import { RouterView, useRouter } from 'vue-router'
import { type AnchorItem, SAnchor } from 'sax-design-vue'

const router = useRouter()
const items: AnchorItem[] = [
  {
    title: 'Table guides',
    children: [
      { title: 'Data', href: '/table/data' },
      { title: 'Selection', href: '/table/selection' },
      { title: 'Sorting', href: '/table/sorting' },
    ],
  },
]
</script>

<template>
  <aside>
    <SAnchor :items="items" :router="router" />
  </aside>
  <RouterView />
</template>

For application-wide reuse, provide the router once when installing Sax Design Vue. A local router prop always takes precedence:

import { type Component, createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import SaxDesignVue, { type AnchorRouterAdapter } from 'sax-design-vue'
import App from './App.vue'

const routeLoaders: Record<string, () => Promise<{ default: Component }>> = {
  '/table/data': () => import('./DataGuide.vue'),
  '/table/selection': () => import('./SelectionGuide.vue'),
  '/table/sorting': () => import('./SortingGuide.vue'),
}
const router = createRouter({
  history: createWebHistory(),
  routes: Object.entries(routeLoaders).map(([path, component]) => ({
    path,
    component,
  })),
})
const anchorRouter: AnchorRouterAdapter = {
  currentRoute: router.currentRoute,
  push: (href) => router.push(href),
  replace: (href) => router.replace(href),
  prefetch: (href) => routeLoaders[router.resolve(href).path]?.(),
}
const app = createApp(App)

app.use(router)
app.use(SaxDesignVue, {
  anchor: {
    router: anchorRouter,
    routePrefetch: true,
    activeStrategy: 'visible-section',
    activeOffset: 160,
    routeBoundary: {
      threshold: 160,
      armDelay: 320,
      routeCooldown: 1500,
    },
  },
})

Set :route-boundary="false" to disable edge scrolling for one Anchor, or pass an object to override the boundary thresholds locally. Routers with another API can be adapted once with { current, push, replace, prefetch }; omit prefetch when route prefetching is not used.

import type { AnchorRouterAdapter } from 'sax-design-vue'

const routerAdapter: AnchorRouterAdapter = {
  current: () => customRouter.location.value,
  push: (href) => customRouter.go(href),
  replace: (href) => customRouter.replaceWith(href),
}

current() should read reactive route state. If the router exposes no reactive location, synchronize the active route through Anchor’s v-model instead.

Scroll container

Local anchors and route-aware outlines both listen to the page window by default. For a panel or virtualized page, provide get-container and return that scrolling element. Anchor navigation, active-state calculation and route boundaries then use the same container.

Scrolling long navigation

Vertical navigation follows the available viewport height, or an explicit max-height. Its outside Scrollbar supports wheel, keyboard and thumb dragging. Scrolling at either navigation edge does not trigger page route transitions.

API

API

PROPS

Property
Type
Values
Description
default
Example
More
v-model
String
href
Active anchor href.
''
—
items
Array
{ href?titledisabled?boundary?collapsible?defaultCollapsed?children? }[]
Recursive navigation items. Omit href for a grouping label;
[]
—
router
{ pushreplace?prefetch?current?currentRoute? }
Router used by this Anchor. Local configuration overrides global anchor.router and structurally supports Vue Router-compatible routers.
—
—
route-prefetch
Boolean
true / false
Prefetches the adjacent route modules while idle through router.prefetch. Local configuration overrides global anchor.routePrefetch.
false
—
route-boundary
Boolean | 
—
Automatic floating previous/next boundary for the flattened eligible route sequence; false disables it, or configure threshold, armDelay and routeCooldown.
true
—
offset
Number
pixels
Reading viewport top inset; also the legacy heading activation offset and click destination fallback when their dedicated props are omitted.
88
—
active-strategy
String
heading / visible-section
Choose the heading-crossing rule or the section occupying most of the readable viewport. Local value overrides global anchor.activeStrategy.
heading
—
active-offset
Number
pixels
Heading activation line measured from the scroll viewport top. Local value overrides global anchor.activeOffset; omitted value falls back to offset.
offset
—
target-offset
Number
pixels
Scroll destination inset after selecting a hash link; defaults to offset.
offset
—
bounds
Number
pixels
Detection tolerance around the heading line and page-bottom boundary.
5
—
max-height
String | Number
—
Maximum height of the vertical navigation. By default, it follows the available viewport height. Overflow uses the built-in Scrollbar with wheel, touch and draggable-thumb scrolling; nested scrolling never advances page route boundaries.
—
—
affix
Boolean
true / false
Keeps the anchor navigation sticky in the viewport.
false
—
get-container
Function
() => HTMLElement | Window
Returns the scroll container. Defaults to the page window.
window
—
get-current-anchor
Function
(activeHref) => href
Lets you override the highlighted href.
undefined
—
replace
Boolean
true / false
Replaces browser history instead of appending a hash entry.
false
—
direction
String
vertical / horizontal
Anchor layout direction. Nested items are available in vertical mode.
vertical
—
scroll-behavior
String
auto / smooth
Scroll behavior after selecting an anchor.
smooth
—

EVENTS

Event
Type
Description
default
Example
More
change
—
Fired when the active anchor changes.
—
—
click
—
Fired with the selected item and MouseEvent before navigation; ordinary same-origin route clicks are then delegated to the configured adapter.
—
—
collapse-change
—
Fired when a collapsible item opens or closes, with the item and collapsed state.
—
—

SLOTS

Slot
Scope
Description
default
Example
More
active-icon
{ item: ; href: string }
Replaces the active marker. It takes precedence over the global Anchor icon.
—
—
route-previous
Replaces the automatic previous-route copy while keeping its link, icon and progress indicator.
—
—
route-next
Replaces the automatic next-route copy while keeping its link, icon and progress indicator.
—
—
Last Updated: 2026-10-28, 06:17:56 UTC
Copied