官方脚手架命令会随版本变化,优先参考最新文档。常见方式:
npm create tanstack@latest
或使用 Bun:
bun create tanstack
选择模板时确认:框架为 React、启用 Start、构建工具为 Vite 或 Rsbuild。
{ "dependencies": { "@tanstack/react-start": "<pin-exact-version>", "@tanstack/react-router": "<pin-exact-version>", "@tanstack/router-plugin": "<pin-exact-version>", "react": "^19.0.0", "react-dom": "^19.0.0" } }
RC 阶段建议锁定精确版本,避免小版本变化影响路由生成或服务端函数。
src/ ├── routes/ │ ├── __root.tsx │ ├── index.tsx │ └── posts.$postId.tsx ├── routeTree.gen.ts ├── router.tsx └── start.ts
routes/
__root.tsx
Outlet
routeTree.gen.ts
router.tsx
start.ts
import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { tanstackStart } from '@tanstack/react-start/plugin/vite' import { TanStackRouterVite } from '@tanstack/router-plugin/vite' export default defineConfig({ plugins: [TanStackRouterVite(), tanstackStart(), react()], })
插件顺序和包名以官方模板为准。