Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)7.6k · #13146

client-side-routing

Skill này làm gì

Skill này giải thích cách thêm trang vào ứng dụng Agent-Native mà vẫn giữ vỏ dùng chung được gắn. Vỏ bao gồm thanh bên agent và điều hướng. Skill dành cho lập trình viên thêm route vào các ứng dụng React này.

Khi nào nên dùng

  • ✓Khi bạn thêm một trang mới vào ứng dụng Agent-Native.
  • ✓Khi thanh bên agent tải lại mỗi lần người dùng đổi trang.
  • ✓Khi bạn cần chọn giữa layout gốc và route layout không có đường dẫn.

Liên kết skill

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/client-side-routing/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/client-side-routing/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể thêm một trang báo cáo mới vào ứng dụng mà thanh bên agent không tải lại khi tôi điều hướng tới đó không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent gắn vỏ dùng chung một lần phía trên vùng hiển thị trang, và dùng route layout không có đường dẫn khi một số trang là công khai còn số khác là riêng tư.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Client-Side Routing

Rule

All templates are single-page apps using React Router. Navigation must not remount the app shell. The agent sidebar, document tree, and any other persistent chrome must survive route changes.

Why

If the shell unmounts on every navigation, the agent chat reconnects/reloads, destroying in-progress work and hammering the backend.

Hard Rule

The app shell (AgentSidebar + any top-level navigation) must be mounted ONCE, above the <Outlet />. Never wrap each page in its own <AppLayout> / <Layout>. React sees a different component at the outlet position on each nav and unmounts the entire subtree.

Two Correct Patterns

1. All routes need the shell

Mount <AppLayout> in root.tsx around <Outlet />:

// app/root.tsx
<AppLayout>
  <Outlet />
</AppLayout>

2. Mix of protected and public routes

Use a React Router pathless layout route:

app/routes/
  _app.tsx                  # renders <AppLayout><Outlet /></AppLayout>
  _app._index.tsx           # / → under AppLayout
  _app.settings.tsx         # /settings → under AppLayout
  _app.team.tsx             # /team → under AppLayout
  book.$slug.tsx            # /book/:slug → no layout (public)
  f.$.tsx                   # /f/* → no layout (public form filler)

The _ prefix on _app.tsx makes it a pathless parent — it contributes the layout but no URL segment. Route files prefixed with _app. nest under it and share the layout instance across navigations.

Anti-Pattern

// ❌ BAD — each route wraps its own Layout, causing full remount on every nav
export default function Settings() {
  return (
    <AppLayout>
      <SettingsContent />
    </AppLayout>
  );
}

If a page needs per-route data (e.g. sidebar highlighting the active document), derive it inside the layout from useParams() / useLocation() — don't pass it as a prop through every route file.

Chat-First Routes

If / is a full-page chat such as AgentChatHome, keep the app shell mounted around it when possible so AgentSidebar URL sync and route warmup stay active. If the chat route intentionally lives outside the shell, add a tiny app-owned prewarm for the routes agents commonly open from that chat. In local dev, React Router can update the address bar before a cold Vite route chunk commits, which makes navigation look broken even when the URL is correct.

Adding a New Route

  • Pattern #1 (AppLayout in root.tsx): just render page content — nothing else.
  • Pattern #2 (pathless _app.tsx): name the file _app.<segment>.tsx for authed routes, or bare <segment>.tsx for public routes.

Related Skills

  • adding-a-feature — The four-area checklist referencing route layout patterns
  • context-awareness — Navigation state written on every route change
Câu hỏi thường gặp

Vì sao thanh bên agent bị tải lại?

Thường xảy ra khi mỗi trang tự bọc trong layout riêng, khiến vỏ bị remount khi điều hướng.

Route layout không có đường dẫn là gì?

Đó là một route cha thêm layout mà không thêm phần nào vào địa chỉ web.

Framework nào được dùng?

Skill nói các ứng dụng dùng React Router như các single page app.

Chi tiết

Mô tả gốc của tác giả

How to add routes without remounting the app shell. Use when adding a new route, fixing agent sidebar reloads on navigation, or choosing between `root.tsx` layout and pathless `_app.tsx` layout patterns.

repo: BuilderIO/agent-native

Độ phổ biến

Sao GitHub
7.6k
Vị trí xếp hạng
#13146
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự