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.

referencessearch-params.md

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

Search params

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

Validation

import { z } from 'zod'

const route = createFileRoute('/posts')({
  validateSearch: z.object({
    page: z.number().int().min(1).default(1),
    sort: z.enum(['new', 'top']).default('new'),
  }),
})

Forms also work as validators:

validateSearch: (input: Record<string, unknown>) => {
  const page = Number(input.page ?? 1)
  return { page: Number.isFinite(page) ? page : 1 }
}
  • Input vs output types differ when defaults/fallbacks exist: input is partial (what a URL may carry), output is complete (what components read). Type SearchSchemaInput marks input-side values, e.g. <Link search={{ page: undefined }}> must remain assignable (src/index.tsx:39).
  • Validation adapters for schema libraries provide the same input/output split: @tanstack/zod-adapter, @tanstack/valibot-adapter, @tanstack/arktype-adapter; createSerializationAdapter is the base (src/index.tsx:22).
  • With Zod, prefer fallback(z.number(), 1) over .catch(); .catch() widens the type to unknown and breaks link prop inference.

Reading and writing

const search = useSearch({ from: '/posts' }) // Ref, search.value.page
const navigate = useNavigate({ from: '/posts' })
navigate({ to: '.', search: (prev) => ({ ...prev, page: prev.page + 1 }) })
  • search in navigate/Link may be an object or an updater receiving the current search of the target route.
  • Zod SearchParamError throws when a param cannot be parsed to the schema type (src/index.tsx:271).

Transforming with search.middlewares

Replaces deprecated preSearchFilters/postSearchFilters. Each middleware: ({ search, next }) => search:

import { retainSearchParams, stripSearchParams } from '@tanstack/vue-router'

const layoutRoute = createFileRoute('/posts')({
  validateSearch: schema,
  search: {
    middlewares: [
      retainSearchParams(['filter']),   // keep on descendant navigations
      stripSearchParams(defaults),      // remove keys equal to defaults
    ],
  },
})

Middlewares run for all descendant links; removes manual search: (prev) => ({...prev, ...}) spreading. Docs: https://tanstack.com/router/latest/docs/framework/vue/api/router/RouteOptionsType

Complex types in URLs

Default serialization handles primitives; for arrays/objects/dates use parseSearchWith/stringifySearchWith with e.g. superjson, or a serialization adapter — https://tanstack.com/router/latest/docs/framework/vue/guide/custom-search-param-serialization

Sharing search across routes

Put validateSearch on a layout route (or use context + middlewares) and read it from children with useSearch({ from: layoutPath, strict: false }). How-to: https://tanstack.com/router/latest/docs/framework/vue/how-to/share-search-params-across-routes

Source: SKILL.md on GitHub

1 warning8d3 checks · Risk SAFE
  • Gen Agent Trust Hub9d

    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

  • Snyk9d

    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