Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

docs(layouts): rework the layout section, add default layout #5118

Merged
merged 13 commits into from
Jun 27, 2022

Conversation

Xanlantos
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

The default layout was missing and the documentation could be simplified by adding it. See commit msg for a detailed change list. I hope to be of help, but I have never contributed to Nuxt or any other public project. Please feel free to guide me.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented May 23, 2022

βœ… Deploy Preview for nuxt3-docs ready!

Name Link
πŸ”¨ Latest commit 0992ceb
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62b57e5492ae090008f043ee
😎 Deploy Preview https://deploy-preview-5118--nuxt3-docs.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@atinux atinux requested a review from danielroe May 25, 2022 11:12
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

What do you think about condensing the examples down to:

  1. Layouts without pages
  2. Layouts with pages
  3. Manual control
  4. Changing layout dynamically

I don't think we need separate examples of how to use the default layout if we cover it within the first two examples.

@@ -8,53 +8,72 @@ head.title: Layouts directory

Nuxt provides a customizable layouts framework you can use throughout your application, ideal for extracting common UI or code patterns into reusable layout components.

Layouts are placed in the `layouts/` directory and will be automatically loaded via asynchronous import when used. Layouts are used by setting a `layout` property as part of your page metadata (if you are using the `~/pages` integration), or by using the `<NuxtLayout>` component.
Layouts are placed in the `layouts/` directory and will be automatically loaded via asynchronous import when used. Layouts are used by setting a `layout` property as part of your page metadata or via the default layout `~/layouts/default.vue` (if you are using the `~/pages` integration), or by using the `<NuxtLayout>` component.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Layouts are placed in the `layouts/` directory and will be automatically loaded via asynchronous import when used. Layouts are used by setting a `layout` property as part of your page metadata or via the default layout `~/layouts/default.vue` (if you are using the `~/pages` integration), or by using the `<NuxtLayout>` component.
Layouts are placed in the `layouts/` directory and will be automatically loaded via asynchronous import when used. Layouts are used by setting a `layout` property as part of your page metadata (if you are using the `~/pages` integration), or by using the `<NuxtLayout>` component.
If you do not set a layout explicitly, then `~/layouts/default.vue` will be used.

Copy link
Contributor Author

@Xanlantos Xanlantos May 25, 2022

Choose a reason for hiding this comment

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

What would be an example for multiple Layouts without pages that is not better done by adapting the app.vue?

  • A "dark/light mode" is more of a CSS thing.
  • A simple menu is better done within the app.vue.
  • A login button I rather see in the app.vue
  • A Logo is also better to keep it simple and in the app.vue
  • A massive complex layout is better split into multiple components anyhow

The only reasonable thing I can come up with is something like:

  • two different menus for the same content, i.e. "top aligned menu" vs "sidebar"

I'd say that's a pretty niche thing, and technically you still could do it better with CSS-grid! So If I am not mistaken I'd say Layouts almost always mean you are using pages already. If I am mistaken please tell me. But if I am right I rather put that first and make a note, towards the end of the page, about how you could do it, if you are not using pages.

Considering that I would rework it to:

Default Layout -> cause it is the easiest way to get in
Multiple Layouts -> cause that's the next likely thing
Layouts without pages -> cause now we covered the basics and the reader does not get confused if we introduce new concepts
Changing layout dynamically -> I think this first as it is more likely to be needed in my opinion but I am fine swapping it with the last
Manual control -> This feels more like abusing the system and should only be done with proper care maybe even add a warning or at least formulate it as a "technical possibility" and less like an "actual option" an expert can ignore it anyway

Maybe the question, in general, is what are layouts for? Cause technically you can use it in various ways. You could even recreate them with components. But why should we use layouts over that? I don't know the answer on a board Nuxt level. I think layouts are nice to get rid of code duplication and have a proper space for it that is different from components. But honestly, that feels still like a bit of a wishy-washy answer. So if you know maybe you can enlighten me.

Sorry for the wall of Text :)

Copy link
Member

Choose a reason for hiding this comment

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

I think it is fair to say we can always replace Layouts with Wrapper dynamic components.

Main point of not using pages/ is to have our own non traditional routing. Imagine a small single page dashboard that has a login state. We can leverage default and guest layouts (or default and dashboard) that are automatically switched based on authentication state rather than page route.

@danielroe danielroe added the documentation Improvements or additions to documentation label May 25, 2022
@@ -8,53 +8,72 @@ head.title: Layouts directory

Nuxt provides a customizable layouts framework you can use throughout your application, ideal for extracting common UI or code patterns into reusable layout components.

Layouts are placed in the `layouts/` directory and will be automatically loaded via asynchronous import when used. Layouts are used by setting a `layout` property as part of your page metadata (if you are using the `~/pages` integration), or by using the `<NuxtLayout>` component.
Layouts are placed in the `layouts/` directory and will be automatically loaded via asynchronous import when used. Layouts are used by setting a `layout` property as part of your page metadata or via the default layout `~/layouts/default.vue` (if you are using the `~/pages` integration), or by using the `<NuxtLayout>` component.
Copy link
Member

Choose a reason for hiding this comment

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

I think it is fair to say we can always replace Layouts with Wrapper dynamic components.

Main point of not using pages/ is to have our own non traditional routing. Imagine a small single page dashboard that has a login state. We can leverage default and guest layouts (or default and dashboard) that are automatically switched based on authentication state rather than page route.

```

In your layout files, you'll need to use `<slot />` to define where the content of your layout will be loaded. For example:
Copy link
Member

Choose a reason for hiding this comment

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

Explaining about <slot /> was nice why you think should be removed here?

</NuxtLayout>
</template>
```

## Example: setting the layout with `~/pages`
## Example: setting another layout
Copy link
Member

Choose a reason for hiding this comment

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

Since we started with two with/without pages variants, it was making sense to emphasis this section also applies to usage with pages.

Otherwise we might move using layouts without pages, to the last and assume the rest are using pages to simplify section.

Xanlantos and others added 7 commits June 3, 2022 17:05
* remove the section that explains how to use app.vue cause the example does not work
* rework the layout section and prioritise the default layout to give the "least config example" first.
* reword some other sections to reflect changes.
* add a dynamically to the last section that helps better understand the content of that section
@Xanlantos
Copy link
Contributor Author

Xanlantos commented Jun 3, 2022

I agree with you on most things and really like your example! If that's how it is supposed to be done then I concur. I have updated it to reflect your comments:

  • slot is back, it was a merge error anyway (thanks for spotting it)
  • I put pages further back, I think under these circumstances it is best to be introduced later
  • I added a sub-section "setting another layout with pages" which we could drop if we like
    Additionally I did:
  • I removed "Example" on all headlines as it seems to be only used here and I rather am consistent, but feel free to add them back I don't think they hurt much
  • I hope linting and rebase worked fingers crossed

Enjoy reviewing :)

@Xanlantos
Copy link
Contributor Author

Will this be merged or do I have to do something?

@danielroe danielroe requested a review from pi0 June 24, 2022 09:01
@pi0
Copy link
Member

pi0 commented Jun 27, 2022

Thanks for working on it @Xanlantos @danielroe

@pi0 pi0 merged commit 026903c into nuxt:main Jun 27, 2022
@pi0 pi0 mentioned this pull request Jul 11, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants