Skip to content

Commit ac39caa

Browse files
authored
docs: less disruptive file-based routing guide regarding virtual routes (#2497)
1 parent 1a714f1 commit ac39caa

2 files changed

Lines changed: 3 additions & 38 deletions

File tree

docs/framework/react/guide/file-based-routing.md

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -87,43 +87,8 @@ It's extremely likely that a 100% directory or flat route structure won't be the
8787

8888
Both flat and directory routes can be mixed together to create a route tree that uses the best of both worlds where it makes sense.
8989

90-
## Virtual File Routes
91-
92-
> We'd like to thank the Remix team for [pioneering the concept of virtual file routes](https://www.youtube.com/watch?v=fjTX8hQTlEc&t=730s). We've taken inspiration from their work and adapted it to work with TanStack Router's existing file-based route-tree generation.
93-
94-
Virtual file routes are a powerful concept that allows you to build a route tree programmatically using code that references real files in your project. This can be useful if:
95-
96-
- You have an existing route organization that you want to keep.
97-
- You want to customize the location of your route files.
98-
- You want to completely override TanStack Router's file-based route generation and build your own convention.
99-
100-
Here's a quick example of using virtual file routes to map a route tree to a set of real files in your project:
101-
102-
```tsx
103-
import {
104-
rootRoute,
105-
route,
106-
index,
107-
layout,
108-
physical,
109-
} from '@tanstack/virtual-file-routes'
110-
111-
const virtualRouteConfig = rootRoute('root.tsx', [
112-
index('index.tsx'),
113-
layout('layout.tsx', [
114-
route('/dashboard', 'app/dashboard.tsx', [
115-
index('app/dashboard-index.tsx'),
116-
route('/invoices', 'app/dashboard-invoices.tsx', [
117-
index('app/invoices-index.tsx'),
118-
route('$id', 'app/invoice-detail.tsx'),
119-
]),
120-
]),
121-
physical('/posts', 'posts'),
122-
]),
123-
])
124-
```
125-
126-
For more information on how to configure virtual file routes, see the [Virtual File Routes](./virtual-file-routes.md) guide.
90+
> [!TIP]
91+
> If you find the need to customize the location of your route files or completely override the discovery of routes, you can use [Virtual File Routes](./virtual-file-routes.md) to programmatically build your route tree while still getting the awesome benefits of file-based routing.
12792
12893
## Dynamic Path Params
12994

docs/framework/react/guide/route-trees.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Route trees can be configured using a few different ways:
6464
- [Flat Routes](./file-based-routing.md#flat-routes)
6565
- [Directories](./file-based-routing.md#directory-routes)
6666
- [Mixed Flat Routes and Directories](./file-based-routing.md#mixed-flat-and-directory-routes)
67-
- [Virtual File Routes](./file-based-routing.md#virtual-file-routes)
67+
- [Virtual File Routes](./virtual-file-routes.md)
6868
- [Code-Based Routes](./code-based-routing.md)
6969

7070
Please be sure to check out the full documentation links above for each type of route tree, or just proceed to the next section to get started with file-based routing.

0 commit comments

Comments
 (0)