All skills
skilld-dev avatar

/tanstack-vue-router-skilld

@b9c39cb

Use when writing, debugging, or refactoring code that imports @tanstack/vue-router (TanStack Router for Vue). Covers setup, file-based and code-based routes, composables returning Ref, Link, loaders, search params, SSR, and v1.170.x deprecations.

Use this Skill: https://skilld.dev/gh/skilld-dev/vue-ecosystem-skills/tanstack-vue-router-skilld

This session only. Nothing lands on disk.

referencesdata-loading.md

≈984 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Data loading

Loaders run on the client by default (client-first). For SSR data, see references/ssr.md.

Pipeline

  1. beforeLoad({ context, params, search, location, matches }) — runs before match commit. Return value becomes route context (readable via useRouteContext). Throw redirect() or notFound() to short-circuit.
  2. loaderDeps({ search }) — object keyed by deps; change triggers loader re-run.
  3. loader({ context, params, deps, abortController, cause, preload }) — fetch and return serializable data; read via useLoaderData.

loader may return a promise; the route suspends behind pendingComponent (client renders inside Vue <Suspense>, src/Matches.tsx:53-64).

Context

import { createRootRouteWithContext, createRouter } from '@tanstack/vue-router'

interface RouterContext { queryClient: QueryClient }

const rootRoute = createRootRouteWithContext<RouterContext>()({ component: Root })

const router = createRouter({
  routeTree: rootRoute.addChildren([/* ... */]),
  context: { queryClient }, // type-checked against RouterContext
})

Guide: https://tanstack.com/router/latest/docs/framework/vue/guide/router-context

Redirects

beforeLoad: async ({ context }) => {
  if (!context.auth.isAuthenticated) {
    throw redirect({ to: '/login', search: { redirect: location.href } })
  }
}
  • redirect() options: to, params, search, hash, replace, resetScroll, ignoreBlocker, headers (SSR).
  • In error handlers, re-check before converting: if (isRedirect(error)) throw error.
  • notFound() (or RouteApi.notFound(), src/route.ts:132-134) renders notFoundComponent; notFoundMode (default 'fuzzy'; 'root' sends all 404s to the root) picks where.
  • API: https://tanstack.com/router/latest/docs/framework/vue/api/router/redirectFunction

Deps hygiene

loaderDeps: ({ search: { page, filter } }) => ({ page, filter }),

Returning the whole search object re-runs the loader on any unrelated search change. Guide: https://tanstack.com/router/latest/docs/framework/vue/guide/data-loading#using-loaderdeps-to-access-search-params

Deferred streaming

import { defer } from '@tanstack/vue-router'

loader: () => ({ critical: await fetchPost(), slow: defer(fetchComments()) })

Consume in a component:

<Suspense>
  <template #default><Comments :promise="data.value.slow" /></template>
  <template #fallback><Spinner /></template>
</Suspense>

<Await :promise="p"> resolves it via async setup and passes data to its children function (src/awaited.tsx:26-43); useAwaited({ promise }) is the hook form. Guide: https://tanstack.com/router/latest/docs/framework/vue/guide/deferred-data-loading

Consumption

Caching windows

Per-route staleTime, preloadStaleTime, gcTime; router defaults defaultStaleTime (default 0), defaultPreloadStaleTime, defaultGsTime. Preloaded routes within defaultPreloadMaxAge (30 s) are cached.

Errors

errorComponent: ({ error, reset }) => VNode; onCatch logs; defaultErrorComponent/defaultOnCatch set router-wide. Uncaught errors hit the global boundary unless disableGlobalCatchBoundary (src/Matches.tsx:104-121). Guide: https://tanstack.com/router/latest/docs/framework/vue/guide/data-loading#handling-errors-with-routeoptionserrorcomponent

Source: SKILL.md on GitHub

1 warning8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    The skill is a comprehensive collection of documentation, API references, and guides for the TanStack Router library. It provides technical information and best practices for implementing routing in web applications. No malicious code, prompt injections, or data exfiltration patterns were detected.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: MEDIUM · 1 issue

Signed by skilld at b9c39cb. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated last week

README badge

README badge for skilld-dev/vue-ecosystem-skills/tanstack-vue-router-skilld