Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: route groups #572

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
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
```
posva marked this conversation as resolved.
Show resolved Hide resolved

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.
posva marked this conversation as resolved.
Show resolved Hide resolved

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