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.