Skip to content

Commit 19c5867

Browse files
docs: route groups (#572)
Co-authored-by: Eduardo San Martin Morote <[email protected]>
1 parent ca1017a commit 19c5867

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/guide/file-based-routing.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,39 @@ const routes = [
109109

110110
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.
111111

112+
## Route groups
113+
114+
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:
115+
116+
```text
117+
src/pages/
118+
├── (admin)/
119+
│   ├── dashboard.vue
120+
│   └── settings.vue
121+
└── (user)/
122+
   ├── profile.vue
123+
  └── order.vue
124+
```
125+
126+
Resulting URLs:
127+
```text
128+
- `/dashboard` -> renders `src/pages/(admin)/dashboard.vue`
129+
- `/settings` -> renders `src/pages/(admin)/settings.vue`
130+
- `/profile` -> renders `src/pages/(user)/profile.vue`
131+
- `/order` -> renders `src/pages/(user)/order.vue`
132+
```
133+
134+
This approach allows you to organize your files for better maintainability without changing the structure of your application's routes.
135+
136+
You can also use route groups in page components. This is equivalent to name the page component `index.vue`:
137+
138+
```text
139+
src/pages/
140+
└─── admin/
141+
   ├── (dashboard).vue // Becomes index.vue of admin route
142+
   └── settings.vue
143+
```
144+
112145
## Named views
113146

114147
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:

0 commit comments

Comments
 (0)