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

Update documentation about nested directories components #1279

Merged
merged 6 commits into from
Feb 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions content/en/guides/directory-structure/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,46 +153,37 @@ If you have components in nested directories such as:
```bash
components/
base/
Button.vue
foo/
Button.vue
```

The component name will be based on its own filename. Therefore, the component will be:
The component name will be based on its own path directory and filename. Therefore, the component will be:

```html
<button />
<BaseFooButton />
```

We recommend you use the directory name in the filename for clarity:
However, if you want to use custom directory strcture that should not be part of component name, can explicitly specify these directories:

```bash
components/
base/
BaseButton.vue
```

However, if you want to keep the filename as `Button.vue`, then you can use the `prefix` option in `nuxt.config` to add a prefix to all components in a specific folder.

```bash
components/
base/
Button.vue
foo/
Button.vue
```

```bash{}[nuxt.config.js]
components: {
dirs: [
'~/components',
{
path: '~/components/base/',
prefix: 'Base'
}
'~/components/base'
]
}
```

And now in your template you can use `BaseButton` instead of `Button` without having to make changes to the name of your `Button.vue` file.
And now in your template you can use `FooButton` instead of `BaseFooButton`.

```html{}[pages/index.vue]
<BaseButton />
<FooButton />
```
<base-alert type="next">Learn more about the [components module](/blog/improve-your-developer-experience-with-nuxt-components).</base-alert>