Remix
约 2 分钟阅读
- remix-run/remixGitHubremix-run/remixremix-run/remix · 基于 React 的开发框架 · 内置 form 处理 · 类似 NextJS · loader -> Compoent -> action · serverBuildTarget · 默认 node-cjs笔记:Remix
- 基于 React 的开发框架
- 内置 form 处理
- 类似 NextJS
- loader -> Compoent -> action
- serverBuildTarget
- 默认 node-cjs
- arc, cloudflare-pages, cloudflare-workers, deno, netlify, node-cjs, vercel,
- 参考
- HMR 有问题
- #7466GitHub Issueremix-run/remix#7466
#1601GitHub Issueremix-run/remix#1601
- 框架耦合程度:
remix > nextjs > vite- nextjs 13 - 增加了 app、server action 后复杂度大大提升
npm add @remix-run/node @remix-run/react @remix-run/serve
npm add -D @remix-run/dev
npx create-remix@latest
npx @remix-run/dev routes --config vite.remix.config.ts
# 只想用 remix 的 filebase routing 结构
pnpm dlx @remix-run/dev routes --config vite.remix.config.ts --jsonPackages@remix-run/nodenpm Package@remix-run/nodeNPM@remix-run/reactnpm Package@remix-run/reactNPM@remix-run/servenpm Package@remix-run/serveNPM@remix-run/devnpm Package@remix-run/devNPM
routes
- app/root.tsx - 顶层 layout
- 路由规则 app/routes
SEGMENT.tsx或 目录SEGMENT/_index.tsxA.B.tsx或者A/B.tsx$var- 路径上变量- exports - Route Module
- loader - 在 GET 请求时执行
- action - 在 DELETE, PATCH, POST, PUT 请求时执行
- clientLoader
- clientAction
- default - 组件
- headers
- meta
- links
- ErrorBoundary
- handle - 路由元数据信息
- HydrateFallback - 在 clientLoader 时显示
- shouldRevalidate
*.client.tsx,*.server.tsx
export async function loader({ request }) {
return getProjects();
}
export async function action({ request }) {
const form = await request.formData();
return createProject({ title: form.get('title') });
}
export default function Projects() {
const projects = useLoaderData();
const { state } = useTransition();
const busy = state === 'submitting';
return (
<div>
{projects.map((project) => (
<Link to={project.slug}>{project.title}</Link>
))}
<Form method='post'>
<input name='title' />
<button type='submit' disabled={busy}>
{busy ? 'Creating...' : 'Create New Project'}
</button>
</Form>
</div>
);
}参考
- app/routes.ts
import { type RoutesConfig, route, layout, index } from "@react-router/dev/routes";- brookslybrand/route-convention-evolutionGitHubbrookslybrand/route-convention-evolution
- Add support for routes.ts remix-run/react-router#11773GitHub PRremix-run/react-router#11773
- @react-router/dev
- remix.run/docs/en/main/discussion/routes
- remix.run/docs/en/main/file-conventions/routes
- interactive-remix-routing-v2.netlify.app
- kiliman/remix-flat-routesGitHubkiliman/remix-flat-routes
- v1 的 routing 结构
- kiliman/remix-flat-routes#39GitHubkiliman/remix-flat-routes/discussions/39 Deprecate remix-flat-routes in favor of remix-hybrid-routes
- v1 和 v2 的 routing 有很大的不同
remix.config.js
vite
关联信息
反向链接、本文链接的其他页面和外部资料。
反向链接
- Web Awesome笔记 · remix
https://www.c82.net/iconography/ · https://www.photopea.com/ · ryohey/signal · MIT, TS · Online MIDI Editor: signal · http://oskarstalberg.com/Townscaper/
References
GitHub8 条
- brookslybrand/route-convention-evolutiongithub.com/brookslybrand/route-convention-evolution
- kiliman/remix-flat-routesgithub.com/kiliman/remix-flat-routes
- kiliman/remix-flat-routes/discussions/39github.com/kiliman/remix-flat-routes/discussions/39
- remix-run/react-router#11773github.com/remix-run/react-router/pull/11773
- remix-run/remixgithub.com/remix-run/remix
- remix-run/remix/templates/unstable-vitegithub.com/remix-run/remix/tree/main/templates/unstable-vite
- remix-run/remix#1601github.com/remix-run/remix/issues/1601
- remix-run/remix#7466github.com/remix-run/remix/issues/7466
其他外链5 条
- interactive-remix-routing-v2.netlify.appinteractive-remix-routing-v2.netlify.app/
- remix.run/blog/remix-vs-nextremix.run/blog/remix-vs-next
- remix.run/docs/en/main/discussion/routesremix.run/docs/en/main/discussion/routes
- remix.run/docs/en/main/file-conventions/remix-configremix.run/docs/en/main/file-conventions/remix-config
- remix.run/docs/en/main/file-conventions/routesremix.run/docs/en/main/file-conventions/routes