-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-router.mdc
More file actions
55 lines (40 loc) · 1.41 KB
/
react-router.mdc
File metadata and controls
55 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
description: React Router 7 routing, loaders, actions, and component patterns
globs: apps/**/app/routes/**/*.tsx, apps/**/app/**/*.tsx
alwaysApply: true
---
# React Router 7 Cursor Rules
## Route Structure
- Use file-based routing in `app/routes/`
- Route files should export default component and optional meta, loader, action functions
- Use `+types` for route-specific TypeScript types
## Component Patterns
```tsx
// Route component example
import type { Route } from './+types/home';
export const meta: Route.MetaFunction = () => {
return [
{ title: 'Page Title' },
{ name: 'description', content: 'Page description' }
];
};
export default function Home() {
return <div>Content</div>;
}
```
## Data Loading
- Use loaders for server-side data fetching
- Use actions for form submissions and mutations
- Prefer server-side data loading over client-side when possible
## Error Handling
- Implement ErrorBoundary components for route-level error handling
- Use isRouteErrorResponse for proper error type checking
## Navigation
- Use Link component for internal navigation
- Use NavLink for navigation with active states
- Prefer declarative navigation over imperative
## Best Practices
- Keep route components focused on layout and data orchestration
- Extract business logic into custom hooks or utilities
- Use proper TypeScript types from route type definitions
- Implement proper loading and error states