Skip to content

Composables

All composables listed here are auto-imported — no import statements needed.

useNavigate

Programmatic navigation function.

ts
const navigate = useNavigate()

// Navigate to path
navigate('/about')

// Navigate with route name
navigate({ name: 'posts-id', params: { id: '123' } })

// Replace instead of push
navigate('/about', { replace: true })

Returns: (to: RouteLocationRaw, options?: NavigateOptions) => Promise<void>

Source: @kimesh/router-runtime


useParams

Access current route params (non-reactive snapshot).

ts
const params = useParams()
console.log(params.id) // string

Source: @kimesh/router-runtime


useReactiveParams

Access current route params as a reactive computed ref.

ts
const params = useReactiveParams<'/posts/:id'>()
// params.value.id — reactive, updates on navigation

Returns: ComputedRef<RouteParams>

Source: @kimesh/router-runtime


useSearch

Access validated search/query params from validateSearch.

ts
// In a route with validateSearch defined
const search = useSearch<'/posts'>()
console.log(search.value.page)   // number
console.log(search.value.sort)   // 'asc' | 'desc'

Returns: ComputedRef<SearchSchema>

Source: @kimesh/router-runtime


useRouteQuery

Two-way binding for a single URL query parameter.

ts
const page = useRouteQuery('page', '1')
// page.value = '2' → URL becomes ?page=2

Signature:

ts
function useRouteQuery(
  key: string,
  defaultValue?: string,
  options?: UseRouteQueryOptions
): Ref<string>

Source: @kimesh/router-runtime


useRouteQueryNumber

Two-way binding for a numeric query parameter.

ts
const page = useRouteQueryNumber('page', 1)
// page.value = 2 → URL becomes ?page=2

Source: @kimesh/router-runtime


useRouteQueryBoolean

Two-way binding for a boolean query parameter.

ts
const showAll = useRouteQueryBoolean('showAll', false)
// showAll.value = true → URL becomes ?showAll=true

Source: @kimesh/router-runtime


Data Loading

useLoaderData

Access data returned from the current route's loader function.

ts
const data = useLoaderData<{ post: Post }>()
console.log(data.value.post)

Returns: Ref<T>

Source: @kimesh/router-runtime


useLayoutData

Access data from the parent layout's loader.

ts
const layoutData = useLayoutData<{ categories: Category[] }>()
console.log(layoutData.value?.categories)

Returns: Ref<T | undefined>

Source: @kimesh/router-runtime


useMatchLoaderData

Access loader data from a specific matched route.

ts
const postsData = useMatchLoaderData<PostsData>('/posts')

Source: @kimesh/router-runtime


useRouteLoaderData

Access all matched route loader data as a map.

ts
const allData = useRouteLoaderData()
// allData.value = { '/posts': {...}, '/posts/:id': {...} }

Source: @kimesh/router-runtime


Data Fetching

useQuery

TanStack Query composable for data fetching with caching.

ts
const { data, isLoading, error, refetch } = useQuery({
  queryKey: ['posts'],
  queryFn: () => fetch('/api/posts').then(r => r.json()),
})

Re-exported from: @tanstack/vue-query


useMutation

TanStack Query composable for mutations.

ts
const { mutate, isPending } = useMutation({
  mutationFn: (newPost) => fetch('/api/posts', {
    method: 'POST',
    body: JSON.stringify(newPost),
  }),
})

Re-exported from: @tanstack/vue-query


useQueryClient

Access the TanStack Query client instance.

ts
const queryClient = useQueryClient()
queryClient.invalidateQueries({ queryKey: ['posts'] })

Re-exported from: @tanstack/vue-query


useInfiniteQuery

TanStack Query composable for infinite/paginated queries.

ts
const { data, fetchNextPage, hasNextPage } = useInfiniteQuery({
  queryKey: ['posts'],
  queryFn: ({ pageParam }) => fetchPosts(pageParam),
  getNextPageParam: (lastPage) => lastPage.nextCursor,
  initialPageParam: 0,
})

Re-exported from: @tanstack/vue-query


useSuspenseQuery

Suspense-compatible query that triggers Vue's <Suspense> boundary.

vue
<script setup>
// Top-level await triggers Suspense
const { data } = await useSuspenseQuery({
  queryKey: ['posts'],
  queryFn: fetchPosts,
})
</script>

Source: @kimesh/query


useSuspenseInfiniteQuery

Suspense-compatible infinite query.

vue
<script setup>
const { data, fetchNextPage } = await useSuspenseInfiniteQuery({
  queryKey: ['posts'],
  queryFn: ({ pageParam }) => fetchPosts(pageParam),
  getNextPageParam: (lastPage) => lastPage.nextCursor,
  initialPageParam: 0,
})
</script>

Source: @kimesh/query


useKmFetch

Nuxt-style fetch composable with auto-refresh and caching.

ts
const { data, pending, error, refresh } = useKmFetch('/api/posts')

// With options
const { data } = useKmFetch('/api/posts', {
  method: 'POST',
  body: { page: 1 },
  watch: [page],        // Re-fetch when page changes
  immediate: true,      // Fetch on mount
})

Source: @kimesh/query


useLazyKmFetch

Same as useKmFetch but doesn't block navigation. Fetches in the background.

ts
const { data, pending } = useLazyKmFetch('/api/posts')

Source: @kimesh/query


useKmAsyncData

Nuxt-style async data composable for custom fetch functions.

ts
const { data, pending, error } = useKmAsyncData('posts', () =>
  fetch('/api/posts').then(r => r.json())
)

Source: @kimesh/query


useLazyKmAsyncData

Non-blocking version of useKmAsyncData.

ts
const { data, pending } = useLazyKmAsyncData('posts', fetchPosts)

Source: @kimesh/query


useKmData

Simplified data composable combining fetch + query features.

ts
const { data } = useKmData('posts', fetchPosts)

Source: @kimesh/query


State Management

useState

SSR-friendly reactive state composable.

ts
const count = useState('counter', () => 0)
count.value++

Signature:

ts
function useState<T>(key: string, init?: () => T): Ref<T>

Source: @kimesh/router-runtime


Head Management

useHead

Reactively set <head> tags.

ts
useHead({
  title: 'My Page',
  meta: [
    { name: 'description', content: 'Page description' },
  ],
  link: [
    { rel: 'canonical', href: 'https://example.com/page' },
  ],
})

// Reactive
const title = ref('Loading')
useHead({ title })

Source: @kimesh/head


useSeoMeta

Flat API for SEO meta tags.

ts
useSeoMeta({
  title: 'My Page',
  ogTitle: 'My Page',
  description: 'A description',
  ogDescription: 'A description',
  ogImage: 'https://example.com/image.png',
  twitterCard: 'summary_large_image',
})

Source: @kimesh/head


useHeadSafe

Same as useHead but sanitizes input to prevent XSS.

ts
useHeadSafe({
  title: userInput, // Sanitized
  script: [{ innerHTML: userScript }], // Sanitized
})

Source: @kimesh/head


useRouteHead

Access the computed head configuration for the current route.

ts
const head = useRouteHead()
console.log(head.value.title)

Source: @kimesh/head


App & Config

useRuntimeConfig

Access runtime configuration defined in kimesh.config.ts.

ts
const config = useRuntimeConfig()
console.log(config.apiBase)
console.log(config.features.darkMode)

Source: @kimesh/router-runtime


useKimeshApp

Access the Kimesh app context (Vue app, router, query client).

ts
const { app, router, queryClient } = useKimeshApp()

Source: @kimesh/router-runtime


useNavigationMiddleware

Register a navigation middleware from a component.

ts
useNavigationMiddleware((context) => {
  console.log(`Navigating to ${context.to.path}`)
})

Source: @kimesh/router-runtime


useNavigationGuard

Register a navigation guard from a component.

ts
useNavigationGuard((context) => {
  if (hasUnsavedChanges.value) {
    return confirm('Discard changes?') ? undefined : false
  }
})

Source: @kimesh/router-runtime


useAfterNavigation

Run code after navigation completes.

ts
useAfterNavigation((context) => {
  analytics.track('page_view', { path: context.to.path })
})

Source: @kimesh/router-runtime


Vue Router (Re-exported)

These are re-exported from vue-router for convenience:

useRoute

ts
const route = useRoute()
console.log(route.path, route.params, route.query)

useRouter

ts
const router = useRouter()
router.push('/about')
ts
const { href, isActive, navigate } = useLink({ to: '/about' })

Released under the MIT License.