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.mdSao 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
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
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>.tsxfor authed routes, or bare<segment>.tsxfor public routes.
Related Skills
adding-a-feature— The four-area checklist referencing route layout patternscontext-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
Bình luận
- …
Thêm skill từ kho mã này
design-exploration
7.6kGiúp agent của bạn khám phá nhiều hướng thiết kế giao diện song song, để bạn chọn một hướng rồi tinh chỉnh thiết kế đã chọn.
visual-edit
7.6kGiúp agent của bạn mở một ứng dụng cục bộ đang chạy trong trình chỉnh sửa trực quan, để bạn xem và sửa các màn hình thật cùng nhau.
turn-into-app
7.6kBiến quy trình, bảng tính hoặc dự án thành ứng dụng trực quan có màn hình đầy đủ dữ liệu, với agent làm việc phía sau các điều khiển.
visual-plan
7.6kBiến một kế hoạch viết bằng văn bản thuần thành kế hoạch trực quan tương tác, có sơ đồ, bản đồ file, đoạn code và các câu hỏi còn mở.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.