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

Merged
merged 14 commits into from
Jan 21, 2025
23 changes: 23 additions & 0 deletions docs/guide/file-based-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ 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
posva marked this conversation as resolved.
Show resolved Hide resolved

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.

```text
src/pages/
├── (admin)/
│ ├── dashboard.vue
│ ├── settings.vue
├── (user)/
│ ├── profile.vue
│ ├── orders.vue
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the correct characters like in the other examples. You can also use the tree command (brew install tree)` to print these:

└── vim                                                                                                                                         
    ├── colors                                                                                                                                  
    │   ├── distinguished.vim                                                                                                                   
    │   ├── lucius.vim                                                                                                                          
    │   ├── molokai.vim                                                                                                                         
    │   └── neverness.vim                                                                                                                       
    ├── ftplugin                                                                                                                                
    │   ├── c.vim                                                                                                                               
    │   ├── cpp.vim                                                                                                                             
    │   └── java.vim                                                                                                                            
    └── spell                                                                                                                                   
        ├── en.utf-8.add                                                                                                                        
        ├── en.utf-8.add.spl                                                                                                                    
        ├── es.utf-8.add                                                                                                                        
        ├── es.utf-8.add.spl                                                                                                                    
        ├── es.utf-8.spl                                                                                                                        
        ├── es.utf-8.sug                                                                                                                        
        ├── fr.utf-8.spl                                                                                                                        
        └── fr.utf-8.sug   

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@posva I generated the tree with tree command, and updated the file. Let me know if it's ok now

```
posva marked this conversation as resolved.
Show resolved Hide resolved

You can also use file route groups for better organization. For example:
nemanjamalesija marked this conversation as resolved.
Show resolved Hide resolved

```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
Loading