Skip to content

Commit

Permalink
docs: route groups (#572)
Browse files Browse the repository at this point in the history
Co-authored-by: Eduardo San Martin Morote <[email protected]>
  • Loading branch information
nemanjamalesija and posva authored Jan 21, 2025
1 parent ca1017a commit 19c5867
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/guide/file-based-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,39 @@ const routes = [

All generated routes that have a `component` property will have a `name` property. This avoid accidentally directing your users to a parent route. By default, names are generated using the file path, but you can override this behavior by passing a custom `getRouteName()` function. You will get TypeScript validation almost everywhere, so changing this should be easy.

## Route groups

Sometimes, it helps to organize your file structure in a way that doesn't change the URL of your routes. Route groups let you organize your routes logically, in a way that makes sense to you, without affecting the actual URLs. For example, if you have several routes that share the same layout, you can group them together using route groups. Consider the following file structure:

```text
src/pages/
├── (admin)/
│   ├── dashboard.vue
│   └── settings.vue
└── (user)/
   ├── profile.vue
  └── order.vue
```

Resulting URLs:
```text
- `/dashboard` -> renders `src/pages/(admin)/dashboard.vue`
- `/settings` -> renders `src/pages/(admin)/settings.vue`
- `/profile` -> renders `src/pages/(user)/profile.vue`
- `/order` -> renders `src/pages/(user)/order.vue`
```

This approach allows you to organize your files for better maintainability without changing the structure of your application's routes.

You can also use route groups in page components. This is equivalent to name the page component `index.vue`:

```text
src/pages/
└─── admin/
   ├── (dashboard).vue // Becomes index.vue of admin route
   └── settings.vue
```

## Named views

It is possible to define [named views](https://router.vuejs.org/guide/essentials/named-views.html#named-views) by appending an `@` + a name to their filename, e.g. a file named `src/pages/[email protected]` will generate a route of:
Expand Down

0 comments on commit 19c5867

Please sign in to comment.