docs-i18n 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/admin/dist/server/server.js +32 -32
  2. package/package.json +1 -1
  3. package/template/app/routes/$lang.$project.$version.docs.$.tsx +2 -1
  4. package/template/app/routes/$lang.$project.$version.docs.framework.$framework.$.tsx +2 -0
  5. package/template/app/routes/$lang.$project.$version.docs.tsx +2 -1
  6. package/template/app/routes/$lang.$project.docs.$.tsx +2 -1
  7. package/template/app/routes/$lang.$project.docs.tsx +2 -1
  8. package/template/app/routes/$lang.docs.$.tsx +2 -1
  9. package/template/app/routes/$lang.docs.framework.$framework.$.tsx +2 -0
  10. package/template/app/routes/$lang.docs.tsx +2 -1
  11. package/template/app/utils/content-loader.ts +13 -2
  12. package/template/app/utils/docs.server.ts +17 -15
  13. package/template/content/blog/en/announcing-query-v5.md +110 -0
  14. package/template/content/blog/en/hello-world.md +26 -0
  15. package/template/content/blog/en/i18n-best-practices.md +57 -0
  16. package/template/content/blog/en/react-query-vs-swr.md +100 -0
  17. package/template/content/blog/en/state-management-2024.md +143 -0
  18. package/template/content/blog/en/tanstack-router-1.0.md +121 -0
  19. package/template/content/blog/ja/announcing-query-v5.md +110 -0
  20. package/template/content/blog/ja/hello-world.md +26 -0
  21. package/template/content/blog/zh-hans/announcing-query-v5.md +93 -0
  22. package/template/content/blog/zh-hans/hello-world.md +26 -0
  23. package/template/content/docs-i18n/docs.config.json +25 -0
  24. package/template/content/docs-i18n/en/architecture.md +335 -0
  25. package/template/content/docs-i18n/en/cli.md +13 -1
  26. package/template/content/docs-i18n/en/configuration.md +350 -0
  27. package/template/content/docs-i18n/en/deployment.md +222 -0
  28. package/template/content/docs-i18n/en/getting-started.md +189 -0
  29. package/template/content/docs.config.json +25 -0
  30. package/template/content/en/admin.md +151 -0
  31. package/template/content/en/architecture.md +222 -0
  32. package/template/content/en/cli.md +269 -0
  33. package/template/content/en/configuration.md +331 -0
  34. package/template/content/en/deployment.md +209 -0
  35. package/template/content/en/getting-started.md +168 -0
  36. package/template/content/form/docs.config.json +18 -0
  37. package/template/content/form/en/guides/validation.md +175 -0
  38. package/template/content/form/en/installation.md +63 -0
  39. package/template/content/form/en/overview.md +71 -0
  40. package/template/content/form/en/quick-start.md +121 -0
  41. package/template/content/form/ja/installation.md +63 -0
  42. package/template/content/form/ja/overview.md +71 -0
  43. package/template/content/form/zh-hans/installation.md +63 -0
  44. package/template/content/form/zh-hans/overview.md +71 -0
  45. package/template/content/query/docs.config.json +32 -0
  46. package/template/content/query/en/guides/mutations.md +126 -0
  47. package/template/content/query/en/guides/pagination.md +98 -0
  48. package/template/content/query/en/guides/queries.md +120 -0
  49. package/template/content/query/en/installation.md +78 -0
  50. package/template/content/query/en/overview.md +72 -0
  51. package/template/content/query/en/quick-start.md +108 -0
  52. package/template/content/query/ja/installation.md +78 -0
  53. package/template/content/query/ja/overview.md +72 -0
  54. package/template/content/query/zh-hans/guides/mutations.md +126 -0
  55. package/template/content/query/zh-hans/guides/pagination.md +98 -0
  56. package/template/content/query/zh-hans/guides/queries.md +120 -0
  57. package/template/content/query/zh-hans/installation.md +95 -0
  58. package/template/content/query/zh-hans/overview.md +72 -0
  59. package/template/content/query/zh-hans/quick-start.md +108 -0
  60. package/template/content/router/docs.config.json +18 -0
  61. package/template/content/router/en/guides/routing-concepts.md +131 -0
  62. package/template/content/router/en/installation.md +57 -0
  63. package/template/content/router/en/overview.md +74 -0
  64. package/template/content/router/en/quick-start.md +88 -0
  65. package/template/content/router/ja/installation.md +57 -0
  66. package/template/content/router/ja/overview.md +78 -0
  67. package/template/content/router/zh-hans/guides/routing-concepts.md +131 -0
  68. package/template/content/router/zh-hans/installation.md +57 -0
  69. package/template/content/router/zh-hans/overview.md +81 -0
  70. package/template/content/router/zh-hans/quick-start.md +88 -0
  71. package/template/content/table/docs.config.json +18 -0
  72. package/template/content/table/en/guides/column-definitions.md +135 -0
  73. package/template/content/table/en/installation.md +56 -0
  74. package/template/content/table/en/overview.md +79 -0
  75. package/template/content/table/en/quick-start.md +112 -0
  76. package/template/content/table/ja/installation.md +56 -0
  77. package/template/content/table/ja/overview.md +79 -0
  78. package/template/content/table/zh-hans/installation.md +56 -0
  79. package/template/content/table/zh-hans/overview.md +79 -0
  80. package/template/content/virtual/docs.config.json +18 -0
  81. package/template/content/virtual/en/guides/dynamic-sizing.md +129 -0
  82. package/template/content/virtual/en/installation.md +57 -0
  83. package/template/content/virtual/en/overview.md +74 -0
  84. package/template/content/virtual/en/quick-start.md +114 -0
  85. package/template/content/virtual/ja/installation.md +57 -0
  86. package/template/content/virtual/ja/overview.md +74 -0
  87. package/template/content/virtual/zh-hans/installation.md +57 -0
  88. package/template/content/virtual/zh-hans/overview.md +74 -0
@@ -0,0 +1,74 @@
1
+ ---
2
+ title: TanStack Router Overview
3
+ description: Type-safe routing for React applications with first-class search param support
4
+ ---
5
+
6
+ # TanStack Router
7
+
8
+ TanStack Router is a fully type-safe React router with built-in data fetching, stale-while-revalidate caching, and first-class search param APIs.
9
+
10
+ ## Why TanStack Router?
11
+
12
+ Traditional routers have limited type safety and treat search params as an afterthought. TanStack Router was built from the ground up with type safety and search params as first-class citizens.
13
+
14
+ ## Features
15
+
16
+ - **100% Type-Safe** — Route paths, params, search params, and loaders are all fully typed
17
+ - **Built-in Search Params** — First-class search param management with validation
18
+ - **Data Loading** — Integrated route loaders with stale-while-revalidate caching
19
+ - **Code Splitting** — Automatic route-based code splitting
20
+ - **Nested Layouts** — Nested routes with shared layouts
21
+ - **Devtools** — Dedicated devtools for debugging routes and cache
22
+
23
+ ## Basic Example
24
+
25
+ ```tsx
26
+ import {
27
+ createRouter,
28
+ createRoute,
29
+ createRootRoute,
30
+ } from '@tanstack/react-router'
31
+
32
+ const rootRoute = createRootRoute({
33
+ component: () => (
34
+ <div>
35
+ <nav>
36
+ <Link to="/">Home</Link>
37
+ <Link to="/about">About</Link>
38
+ </nav>
39
+ <Outlet />
40
+ </div>
41
+ ),
42
+ })
43
+
44
+ const indexRoute = createRoute({
45
+ getParentRoute: () => rootRoute,
46
+ path: '/',
47
+ component: () => <div>Welcome Home!</div>,
48
+ })
49
+
50
+ const aboutRoute = createRoute({
51
+ getParentRoute: () => rootRoute,
52
+ path: '/about',
53
+ component: () => <div>About</div>,
54
+ })
55
+
56
+ const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])
57
+
58
+ const router = createRouter({ routeTree })
59
+ ```
60
+
61
+ ## Type-Safe Search Params
62
+
63
+ ```tsx
64
+ const productsRoute = createRoute({
65
+ getParentRoute: () => rootRoute,
66
+ path: '/products',
67
+ validateSearch: (search) => ({
68
+ page: Number(search.page ?? 1),
69
+ filter: (search.filter as string) ?? '',
70
+ sort: (search.sort as 'asc' | 'desc') ?? 'asc',
71
+ }),
72
+ component: ProductsPage,
73
+ })
74
+ ```
@@ -0,0 +1,88 @@
1
+ ---
2
+ title: Quick Start
3
+ description: Get up and running with TanStack Router in minutes
4
+ ---
5
+
6
+ # Quick Start
7
+
8
+ ## File-Based Routing
9
+
10
+ The easiest way to get started is with file-based routing. Create your routes directory:
11
+
12
+ ```
13
+ src/
14
+ routes/
15
+ __root.tsx
16
+ index.tsx
17
+ about.tsx
18
+ posts/
19
+ index.tsx
20
+ $postId.tsx
21
+ ```
22
+
23
+ ### Root Route
24
+
25
+ ```tsx
26
+ // src/routes/__root.tsx
27
+ import { createRootRoute, Link, Outlet } from '@tanstack/react-router'
28
+
29
+ export const Route = createRootRoute({
30
+ component: () => (
31
+ <>
32
+ <nav>
33
+ <Link to="/">Home</Link>
34
+ <Link to="/about">About</Link>
35
+ <Link to="/posts">Posts</Link>
36
+ </nav>
37
+ <Outlet />
38
+ </>
39
+ ),
40
+ })
41
+ ```
42
+
43
+ ### Index Route
44
+
45
+ ```tsx
46
+ // src/routes/index.tsx
47
+ import { createFileRoute } from '@tanstack/react-router'
48
+
49
+ export const Route = createFileRoute('/')({
50
+ component: () => <div>Welcome Home!</div>,
51
+ })
52
+ ```
53
+
54
+ ### Dynamic Route
55
+
56
+ ```tsx
57
+ // src/routes/posts/$postId.tsx
58
+ import { createFileRoute } from '@tanstack/react-router'
59
+
60
+ export const Route = createFileRoute('/posts/$postId')({
61
+ loader: async ({ params }) => {
62
+ return fetchPost(params.postId)
63
+ },
64
+ component: PostPage,
65
+ })
66
+
67
+ function PostPage() {
68
+ const post = Route.useLoaderData()
69
+ return <div>{post.title}</div>
70
+ }
71
+ ```
72
+
73
+ ## Data Loading
74
+
75
+ TanStack Router supports route-level data loading with caching:
76
+
77
+ ```tsx
78
+ export const Route = createFileRoute('/posts')({
79
+ loader: async () => {
80
+ const posts = await fetch('/api/posts').then((r) => r.json())
81
+ return { posts }
82
+ },
83
+ component: PostsPage,
84
+ })
85
+ ```
86
+
87
+ > [!NOTE]
88
+ > Route loaders run in parallel for nested routes, ensuring the fastest possible data loading.
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: インストール
3
+ description: プロジェクトに TanStack Router をインストールする方法
4
+ ---
5
+
6
+ # インストール
7
+
8
+ ## パッケージのインストール
9
+
10
+ ```bash
11
+ npm install @tanstack/react-router
12
+ ```
13
+
14
+ ```bash
15
+ pnpm add @tanstack/react-router
16
+ ```
17
+
18
+ ```bash
19
+ yarn add @tanstack/react-router
20
+ ```
21
+
22
+ ```bash
23
+ bun add @tanstack/react-router
24
+ ```
25
+
26
+ ## Vite プラグイン(推奨)
27
+
28
+ ファイルベースルーティングと自動ルート生成で最高の体験を得るために、Vite プラグインをインストールしてください:
29
+
30
+ ```bash
31
+ npm install -D @tanstack/router-plugin
32
+ ```
33
+
34
+ `vite.config.ts` に追加します:
35
+
36
+ ```ts
37
+ import { defineConfig } from 'vite'
38
+ import react from '@vitejs/plugin-react'
39
+ import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
40
+
41
+ export default defineConfig({
42
+ plugins: [TanStackRouterVite(), react()],
43
+ })
44
+ ```
45
+
46
+ ## Devtools
47
+
48
+ ルートデバッグ用の devtools をインストールします:
49
+
50
+ ```bash
51
+ npm install @tanstack/router-devtools
52
+ ```
53
+
54
+ ## 必要要件
55
+
56
+ - React 18+
57
+ - TypeScript 5.0+(強く推奨)
@@ -0,0 +1,78 @@
1
+ ---
2
+ title: TanStack Router 概要
3
+ description: Reactアプリケーション向けの型安全なルーティングライブラリ
4
+ ---
5
+
6
+ # TanStack Router
7
+
8
+ TanStack Routerは、Reactアプリケーション向けに設計された完全型安全なルーティングライブラリです。ナビゲーションからサーチパラメータまで、エンドツーエンドの型安全性を提供します。
9
+
10
+ ## なぜTanStack Routerを選ぶのか?
11
+
12
+ 従来のReactルーティングライブラリは型安全性の面で不十分でした。ルートパスは文字列、パラメータは`any`型、サーチパラメータはまったく検証されません。TanStack Routerはこれらの問題を根本から解決します。
13
+
14
+ ## 主な特徴
15
+
16
+ - **100% 型安全** — リンク、ナビゲーション、パラメータ、サーチパラメータすべてが完全に型チェックされる
17
+ - **ファーストクラスのサーチパラメータ** — URLサーチパラメータが検証され型付けされる
18
+ - **組み込みデータローディング** — ルートレベルのデータプリフェッチ
19
+ - **ファイルベースルーティング** — ファイルシステムから型安全なルートツリーを自動生成
20
+ - **ネストされたレイアウト** — ルートのネストで共有レイアウトを作成
21
+ - **コード分割** — ルートごとのコード分割を標準サポート
22
+
23
+ ## クイック例
24
+
25
+ ```tsx
26
+ import {
27
+ createRootRoute,
28
+ createRoute,
29
+ createRouter,
30
+ Link,
31
+ Outlet,
32
+ } from '@tanstack/react-router'
33
+
34
+ const rootRoute = createRootRoute({
35
+ component: () => (
36
+ <div>
37
+ <nav>
38
+ <Link to="/">ホーム</Link>
39
+ <Link to="/about">アバウト</Link>
40
+ </nav>
41
+ <Outlet />
42
+ </div>
43
+ ),
44
+ })
45
+
46
+ const indexRoute = createRoute({
47
+ getParentRoute: () => rootRoute,
48
+ path: '/',
49
+ component: () => <h1>ホームページへようこそ</h1>,
50
+ })
51
+
52
+ const aboutRoute = createRoute({
53
+ getParentRoute: () => rootRoute,
54
+ path: '/about',
55
+ component: () => <h1>私たちについて</h1>,
56
+ })
57
+
58
+ const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])
59
+ const router = createRouter({ routeTree })
60
+ ```
61
+
62
+ ## TanStack Queryとの連携
63
+
64
+ TanStack RouterはTanStack Queryと相性が抜群です。ルートの`loader`でQueryを使用してデータをプリフェッチできます:
65
+
66
+ ```tsx
67
+ const userRoute = createRoute({
68
+ path: '/users/$userId',
69
+ loader: ({ params, context }) =>
70
+ context.queryClient.ensureQueryData({
71
+ queryKey: ['user', params.userId],
72
+ queryFn: () => fetchUser(params.userId),
73
+ }),
74
+ })
75
+ ```
76
+
77
+ > [!NOTE]
78
+ > TanStack Routerは単独で使用することも、TanStack Startと組み合わせてフルスタックフレームワークとして使用することもできます。
@@ -0,0 +1,131 @@
1
+ ---
2
+ title: 路由概念
3
+ description: 了解 TanStack Router 的核心路由概念
4
+ ---
5
+
6
+ # 路由概念
7
+
8
+ TanStack Router 建立在几个核心概念之上,使其功能强大且灵活。理解这些概念将帮助您构建更好的应用。
9
+
10
+ ## 路由树
11
+
12
+ TanStack Router 使用路由树来定义应用的结构。路由可以嵌套以创建布局和层级结构:
13
+
14
+ ```tsx
15
+ import { createRootRoute, createRoute, createRouter } from '@tanstack/react-router'
16
+
17
+ const rootRoute = createRootRoute({
18
+ component: RootLayout,
19
+ })
20
+
21
+ const indexRoute = createRoute({
22
+ getParentRoute: () => rootRoute,
23
+ path: '/',
24
+ component: HomePage,
25
+ })
26
+
27
+ const aboutRoute = createRoute({
28
+ getParentRoute: () => rootRoute,
29
+ path: '/about',
30
+ component: AboutPage,
31
+ })
32
+
33
+ const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])
34
+
35
+ const router = createRouter({ routeTree })
36
+ ```
37
+
38
+ ## 基于文件的路由
39
+
40
+ 对于大多数应用,TanStack Router 通过插件支持基于文件的路由。您的文件结构即是路由结构:
41
+
42
+ ```
43
+ app/
44
+ routes/
45
+ __root.tsx → 根布局
46
+ index.tsx → /
47
+ about.tsx → /about
48
+ posts.tsx → /posts(布局)
49
+ posts.index.tsx → /posts/
50
+ posts.$postId.tsx → /posts/:postId
51
+ ```
52
+
53
+ > [!NOTE]
54
+ > 基于文件的路由由 `@tanstack/router-plugin` 包驱动,它在构建时自动生成路由树。
55
+
56
+ ## 搜索参数
57
+
58
+ TanStack Router 将搜索参数视为一等公民,提供完整的类型安全:
59
+
60
+ ```tsx
61
+ const productsRoute = createRoute({
62
+ getParentRoute: () => rootRoute,
63
+ path: '/products',
64
+ validateSearch: (search: Record<string, unknown>) => {
65
+ return {
66
+ page: Number(search.page) || 1,
67
+ filter: (search.filter as string) || '',
68
+ sort: (search.sort as 'asc' | 'desc') || 'asc',
69
+ }
70
+ },
71
+ component: ProductsPage,
72
+ })
73
+
74
+ function ProductsPage() {
75
+ const { page, filter, sort } = productsRoute.useSearch()
76
+
77
+ return (
78
+ <div>
79
+ <p>页码:{page},筛选:{filter},排序:{sort}</p>
80
+ </div>
81
+ )
82
+ }
83
+ ```
84
+
85
+ ## 数据加载
86
+
87
+ 路由可以定义在渲染前获取数据的加载器:
88
+
89
+ ```tsx
90
+ const postRoute = createRoute({
91
+ getParentRoute: () => postsRoute,
92
+ path: '$postId',
93
+ loader: async ({ params }) => {
94
+ const post = await fetchPost(params.postId)
95
+ return { post }
96
+ },
97
+ component: PostPage,
98
+ })
99
+
100
+ function PostPage() {
101
+ const { post } = postRoute.useLoaderData()
102
+ return <article>{post.title}</article>
103
+ }
104
+ ```
105
+
106
+ | 功能 | 描述 |
107
+ |---|---|
108
+ | 路由树 | 具有父子关系的层级路由定义 |
109
+ | 基于文件的路由 | 从文件系统自动生成路由 |
110
+ | 搜索参数 | 带验证的类型安全 URL 搜索参数 |
111
+ | 数据加载 | 在路由渲染前预取数据 |
112
+ | 等待状态 | 导航期间的内置加载指示器 |
113
+ | 错误边界 | 按路由的错误处理 |
114
+
115
+ ## 路径参数
116
+
117
+ 路径中的动态段以 `$` 为前缀:
118
+
119
+ ```tsx
120
+ // 单个参数
121
+ '/posts/$postId'
122
+
123
+ // 多个参数
124
+ '/users/$userId/posts/$postId'
125
+
126
+ // 通配符/全匹配
127
+ '/files/$'
128
+ ```
129
+
130
+ > [!WARNING]
131
+ > 与其他路由器不同,TanStack Router 不使用 `:` 作为动态段前缀。始终使用 `$` 作为前缀。
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: 安装
3
+ description: 如何在项目中安装 TanStack Router
4
+ ---
5
+
6
+ # 安装
7
+
8
+ ## 安装依赖包
9
+
10
+ ```bash
11
+ npm install @tanstack/react-router
12
+ ```
13
+
14
+ ```bash
15
+ pnpm add @tanstack/react-router
16
+ ```
17
+
18
+ ```bash
19
+ yarn add @tanstack/react-router
20
+ ```
21
+
22
+ ```bash
23
+ bun add @tanstack/react-router
24
+ ```
25
+
26
+ ## Vite 插件(推荐)
27
+
28
+ 为了获得最佳的基于文件路由和自动路由生成体验,请安装 Vite 插件:
29
+
30
+ ```bash
31
+ npm install -D @tanstack/router-plugin
32
+ ```
33
+
34
+ 然后将其添加到 `vite.config.ts` 中:
35
+
36
+ ```ts
37
+ import { defineConfig } from 'vite'
38
+ import react from '@vitejs/plugin-react'
39
+ import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
40
+
41
+ export default defineConfig({
42
+ plugins: [TanStackRouterVite(), react()],
43
+ })
44
+ ```
45
+
46
+ ## 开发工具
47
+
48
+ 安装开发工具用于路由调试:
49
+
50
+ ```bash
51
+ npm install @tanstack/router-devtools
52
+ ```
53
+
54
+ ## 环境要求
55
+
56
+ - React 18+
57
+ - TypeScript 5.0+(强烈推荐)
@@ -0,0 +1,81 @@
1
+ ---
2
+ title: TanStack Router 概述
3
+ description: 为 React 应用打造的类型安全路由库
4
+ ---
5
+
6
+ # TanStack Router
7
+
8
+ TanStack Router 是一个为 React 应用设计的全类型安全路由库。它将路由提升为一等公民,提供从导航到搜索参数的端到端类型安全。
9
+
10
+ ## 为什么选择 TanStack Router?
11
+
12
+ 传统的 React 路由库在类型安全方面存在不足。路由路径是字符串,参数是 `any` 类型,搜索参数完全未经验证。TanStack Router 从根本上解决了这些问题。
13
+
14
+ ## 核心特性
15
+
16
+ - **100% 类型安全** — 链接、导航、参数和搜索参数都经过完整的类型检查
17
+ - **一等搜索参数** — URL 搜索参数经过验证和类型化,如同路径参数一样
18
+ - **内置数据加载** — 路由级别的数据预取,支持 stale-while-revalidate
19
+ - **文件路由** — 通过文件系统结构自动生成类型安全的路由树
20
+ - **嵌套布局** — 路由可嵌套以创建共享布局
21
+ - **代码分割** — 开箱即用的按路由代码分割
22
+
23
+ ## 快速示例
24
+
25
+ ```tsx
26
+ import {
27
+ createRootRoute,
28
+ createRoute,
29
+ createRouter,
30
+ Link,
31
+ Outlet,
32
+ } from '@tanstack/react-router'
33
+
34
+ // 定义根路由
35
+ const rootRoute = createRootRoute({
36
+ component: () => (
37
+ <div>
38
+ <nav>
39
+ <Link to="/">首页</Link>
40
+ <Link to="/about">关于</Link>
41
+ </nav>
42
+ <Outlet />
43
+ </div>
44
+ ),
45
+ })
46
+
47
+ // 定义子路由
48
+ const indexRoute = createRoute({
49
+ getParentRoute: () => rootRoute,
50
+ path: '/',
51
+ component: () => <h1>欢迎来到首页</h1>,
52
+ })
53
+
54
+ const aboutRoute = createRoute({
55
+ getParentRoute: () => rootRoute,
56
+ path: '/about',
57
+ component: () => <h1>关于我们</h1>,
58
+ })
59
+
60
+ // 构建路由树
61
+ const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])
62
+ const router = createRouter({ routeTree })
63
+ ```
64
+
65
+ ## 与 TanStack Query 配合使用
66
+
67
+ TanStack Router 与 TanStack Query 完美配合。在路由的 `loader` 中使用 Query 来预取数据:
68
+
69
+ ```tsx
70
+ const userRoute = createRoute({
71
+ path: '/users/$userId',
72
+ loader: ({ params, context }) =>
73
+ context.queryClient.ensureQueryData({
74
+ queryKey: ['user', params.userId],
75
+ queryFn: () => fetchUser(params.userId),
76
+ }),
77
+ })
78
+ ```
79
+
80
+ > [!NOTE]
81
+ > TanStack Router 可以独立使用,也可以与 TanStack Start 结合使用以获得完整的全栈框架体验。
@@ -0,0 +1,88 @@
1
+ ---
2
+ title: 快速开始
3
+ description: 几分钟内上手 TanStack Router
4
+ ---
5
+
6
+ # 快速开始
7
+
8
+ ## 基于文件的路由
9
+
10
+ 最简单的入门方式是使用基于文件的路由。创建您的路由目录:
11
+
12
+ ```
13
+ src/
14
+ routes/
15
+ __root.tsx
16
+ index.tsx
17
+ about.tsx
18
+ posts/
19
+ index.tsx
20
+ $postId.tsx
21
+ ```
22
+
23
+ ### 根路由
24
+
25
+ ```tsx
26
+ // src/routes/__root.tsx
27
+ import { createRootRoute, Link, Outlet } from '@tanstack/react-router'
28
+
29
+ export const Route = createRootRoute({
30
+ component: () => (
31
+ <>
32
+ <nav>
33
+ <Link to="/">首页</Link>
34
+ <Link to="/about">关于</Link>
35
+ <Link to="/posts">文章</Link>
36
+ </nav>
37
+ <Outlet />
38
+ </>
39
+ ),
40
+ })
41
+ ```
42
+
43
+ ### 索引路由
44
+
45
+ ```tsx
46
+ // src/routes/index.tsx
47
+ import { createFileRoute } from '@tanstack/react-router'
48
+
49
+ export const Route = createFileRoute('/')({
50
+ component: () => <div>欢迎回来!</div>,
51
+ })
52
+ ```
53
+
54
+ ### 动态路由
55
+
56
+ ```tsx
57
+ // src/routes/posts/$postId.tsx
58
+ import { createFileRoute } from '@tanstack/react-router'
59
+
60
+ export const Route = createFileRoute('/posts/$postId')({
61
+ loader: async ({ params }) => {
62
+ return fetchPost(params.postId)
63
+ },
64
+ component: PostPage,
65
+ })
66
+
67
+ function PostPage() {
68
+ const post = Route.useLoaderData()
69
+ return <div>{post.title}</div>
70
+ }
71
+ ```
72
+
73
+ ## 数据加载
74
+
75
+ TanStack Router 支持带缓存的路由级数据加载:
76
+
77
+ ```tsx
78
+ export const Route = createFileRoute('/posts')({
79
+ loader: async () => {
80
+ const posts = await fetch('/api/posts').then((r) => r.json())
81
+ return { posts }
82
+ },
83
+ component: PostsPage,
84
+ })
85
+ ```
86
+
87
+ > [!NOTE]
88
+ > 嵌套路由的路由加载器会并行运行,确保最快的数据加载速度。
@@ -0,0 +1,18 @@
1
+ {
2
+ "sections": [
3
+ {
4
+ "label": "Getting Started",
5
+ "children": [
6
+ { "label": "Overview", "to": "overview" },
7
+ { "label": "Installation", "to": "installation" },
8
+ { "label": "Quick Start", "to": "quick-start" }
9
+ ]
10
+ },
11
+ {
12
+ "label": "Guides",
13
+ "children": [
14
+ { "label": "Column Definitions", "to": "guides/column-definitions" }
15
+ ]
16
+ }
17
+ ]
18
+ }