Back to Router

TanStack Vue Router

packages/vue-router/README.md

1.166.74.4 KB
Original Source

TanStack Vue Router

πŸ€– Type-safe router w/ built-in caching & URL state management for Vue!

<a href="https://twitter.com/intent/tweet?button_hashtag=TanStack" target="\_parent">

</a><a href="https://discord.com/invite/WrRKjPJ" target="\_parent">

</a><a href="https://npmjs.com/package/@tanstack/vue-router" target="\_parent">

</a><a href="https://bundlephobia.com/result?p=@tanstack/vue-router" target="\_parent">

</a><a href="#badge">

</a><a href="https://github.com/TanStack/router/discussions">

</a><a href="https://bestofjs.org/projects/router"></a><a href="https://github.com/TanStack/router" target="\_parent">

</a><a href="https://twitter.com/tan_stack" target="\_parent">

</a><a href="https://twitter.com/tannerlinsley" target="\_parent">

</a>

Visit tanstack.com/router for docs, guides, API and more!

File-Based Routing Conventions

Suffix/PatternPurpose
.route.tsRoute configuration (loader, validateSearch, head, etc.)
.component.vueThe component rendered for the route
.errorComponent.vueError boundary component for the route
.notFoundComponent.vueNot found component for the route
.lazy.tsLazy-loaded route configuration
_layout prefixLayout routes that wrap child routes
_ suffix (e.g., posts_.$postId)Unnested routes (break out of parent layout)
(groupName) directoryRoute groups (organizational, don't affect URL)
$paramDynamic route parameters

Examples from e2e/basic-file-routes/ project

src/routes/
β”œβ”€β”€ __root.ts                   # Root route config
β”œβ”€β”€ __root.component.vue        # Root layout component
β”œβ”€β”€ __root.notFoundComponent.vue # Global not found component
β”œβ”€β”€ index.route.ts              # "/" route config
β”œβ”€β”€ index.component.vue         # "/" component
β”œβ”€β”€ posts.route.ts              # "/posts" route config
β”œβ”€β”€ posts.component.vue         # "/posts" layout component
β”œβ”€β”€ posts.index.component.vue   # "/posts" index component
β”œβ”€β”€ posts.$postId.route.ts      # "/posts/:postId" route config
β”œβ”€β”€ posts.$postId.component.vue # "/posts/:postId" component
β”œβ”€β”€ posts.$postId.errorComponent.vue  # Error boundary for post
β”œβ”€β”€ posts_.$postId.edit.route.ts      # "/posts/:postId/edit" (unnested)
β”œβ”€β”€ (group)/                    # Route group (no URL impact)
β”‚   β”œβ”€β”€ _layout.route.ts        # Layout for group
β”‚   β”œβ”€β”€ _layout.component.vue
β”‚   └── inside.component.vue    # "/inside"
└── λŒ€ν•œλ―Όκ΅­.component.vue        # Unicode routes supported