anhpht06/frontend-skill-pack/04-router
Claude Code and agent skill by anhpht06/frontend-skill-pack
- community
Checking that the SKILL.md file is still in the repository.
Hướng dẫn quy tắc định tuyến, chuyển trang và cấu trúc file trong Next.js App Router.
Install
npx vskill@latest install anhpht06/frontend-skill-pack/04-routerSKILL.md
The same SKILL.md was published earlier as anhpht06/frontend-skill-pack/04-router.
Routing & Navigation with Next.js App Router
Tài liệu này định nghĩa các quy tắc khi làm việc với hệ thống Router của Next.js.
1. Quản lý Route Name
- Toàn bộ các chuỗi định tuyến (URL paths) BẮT BUỘC phải được khai báo tập trung tại file
src/constants/routes.ts. - Tuyệt đối không hardcode chuỗi URL trực tiếp trong Component.
``typescript // src/constants/routes.ts export const ROUTES = { HOME: "/", LOGIN: "/login", PROFILE: (id: string) => /profile/${id}`, };
// ❌ Sai <Link href="/login">Đăng nhập</Link>
// ✅ Đúng <Link href={ROUTES.LOGIN}>Đăng nhập</Link> ```
2. Cấu trúc thư mục App Router (app/)
Tuân thủ nghiêm ngặt các quy ước file đặc biệt của Next.js:
page.tsx: Giao diện chính của route (Server Component mặc định).layout.tsx: Layout bọc ngoài các trang con (Dùng chung Navbar, Sidebar).loading.tsx: Hiển thị Skeleton UI trong lúc chờ lấy dữ liệu.error.tsx: Phải tích hợpAppErrorkèm nút thử lại. Chú ý file này phải có"use client".not-found.tsx: Hiển thị khi truy cập sai URL hoặc gọi hàmnotFound().
3. Bảo vệ Route (Protected Routes)
- Việc kiểm tra xác thực (User đã đăng nhập chưa) để chặn truy cập vào các trang nội bộ phải được thực hiện ở tầng Server qua `middleware.ts`.
- Không thực hiện việc check Auth và Redirect lắt nhắt bên trong từng Component Client (sẽ gây giật nháy màn hình).
4. Chuyển trang (Navigation)
- Dùng
<Link>: Cho các thao tác chuyển trang thông thường từ UI (tốt cho SEO và prefetching). - Dùng
router.push()(từuseRoutercủanext/navigation): Sử dụng sau khi hoàn thành một action (ví dụ: Nút submit form, sau khi đăng nhập thành công). - Dùng
redirect()(từnext/navigation): Sử dụng khi cần chuyển hướng trực tiếp từ Server Component hoặc Route Handler/Server Action.
5. Trạng thái Loading
- Ưu tiên sử dụng
loading.tsxvới Skeleton UI phù hợp với bố cục trang. - Tránh dùng spinner toàn trang (Full-page spinner) gây trải nghiệm người dùng kém (block UI).
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingvi/04-router/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anhpht06/frontend-skill-pack/04-router)