# Nuxt File-Based Routing
## When to Use
Working with `pages/` or `layouts/` directories, file-based routing, navigation.
## File-Based Routing Basics
`pages/` folder structure directly maps to routes. File names determine URLs.
## Naming Conventions
**Key principles:**
- **ALWAYS use descriptive params:** `[userId].vue` NOT `[id].vue`
- **Optional params:** `[[paramName]].vue`
- **Catch-all:** `[...path].vue`
- **Route groups for organization:** `(folder)/` groups files without affecting URLs
## Red Flags - Stop and Check Skill
If you're thinking any of these, STOP and re-read this skill:
- "String paths are simpler than typed routes"
- "Generic param names like [id] are fine"
- "I remember how Nuxt 3 worked"
All of these mean: You're about to use outdated patterns. Use Nuxt 4 patterns instead.
## File Structure Example
```
pages/
├── index.vue # /
├── about.vue # /about
├── [...slug].vue # catch-all for 404
├── users.vue # parent route (layout for /users/*)
└── users/
├── index.vue # /users
└── [userId].vue # /users/:userId
```
## Route Groups for Organization
Route groups organize files WITHOUT affecting URLs. Wrap folder names in parentheses:
```
pages/
├── (marketing)/ # group folder (ignored in URL)
│ ├── about.vue # /about (not /marketing/about)
│ └── pricing.vue # /pricing
└── (admin)/ # group folder (ignored in URL)
├── dashboard.vue # /dashboard
└── settings.vue # /settings
```
**Use route groups to:**
- Organize pages by feature/team
- Group related routes without affecting URLs
- Keep large projects maintainable
- Apply middleware to specific groups (via `route.meta.groups`)
**Access route groups in middleware:**
```ts
// middleware/auth.global.ts
export default defineNuxtRouteMiddleware((to) => {
// Check if route is in admin group
if (to.meta.groups?.includes('admin')) {
const auth = useAuthStore()
if (!auth.isAdmin) return navigateTo('/')
}
})
```
## Parent Routes (Layouts)
Parent route = layout for nested routes:
```vue