Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions docs/content/3.docs/2.directory-structure/4.components.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,40 @@ export default {
</script>
```

## `<ClientOnly>` Component

Nuxt provides the `<ClientOnly>` component for purposely rendering a component only on client-side. To import a component only on the client, register the component in a client-side only plugin.

```html{}[pages/example.vue]
<template>
<div>
<Sidebar />
<ClientOnly>
<!-- this component will only be rendered on client-side -->
<Comments />
</ClientOnly>
</div>
</template>
```

Use a slot as fallback until `<ClientOnly>` is mounted on client-side.

```html{}[pages/example.vue]
<template>
<div>
<Sidebar />
<ClientOnly>
<!-- this component will only be rendered on client-side -->
<Comments />
<template #fallback>
<!-- this will be rendered on server-side -->
<p>Loading comments...</p>
</template>
</ClientOnly>
</div>
</template>
```

## Library Authors

Making Vue component libraries with automatic tree-shaking and component registration is super easy โœจ
Expand Down
68 changes: 40 additions & 28 deletions docs/content/3.docs/2.directory-structure/9.pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,50 @@ Navigating to `/users-admins/123` would render:
admins 123
```

## Nested Routes
## Navigation

We provide a semantic alias for `RouterView`, the `NuxtChild` component, for displaying the children components of a [nested route](https://next.router.vuejs.org/guide/essentials/nested-routes.html).
To navigate between pages of your app, you should use the ย `<NuxtLink>`ย component. This component is included with Nuxt and therefore you don't have to import it like you do with other components. It is similar to the HTML `<a>` tag except that instead of using a `href="/about"` you use `to="/about"`. If you've used `vue-router` before, you can think of `<NuxtLink>` as a replacement of `<RouterLink>`

### Example
A simple link to the `index.vue` page in your `pages` folder:

```bash
-| pages/
---| parent/
------| child.vue
---| parent.vue
```html
<template>
<NuxtLink to="/">Home page</NuxtLink>
</template>
```

To display the `child.vue` component, simply put the `<NuxtChild>` component inside the `parent.vue` component:
The `<NuxtLink>` component should be used for all internal links. That means for all links to the pages within your site you should use `<NuxtLink>`. The `<a>` tag should be used for all external links. That means if you have links to other websites you should use the `<a>` tag for those.

```html{}[pages/parent/child.vue]
```html
<template>
<div>
<h3>child.vue</h3>
<h1>Home page</h1>
<NuxtLink to="/about">
About (internal link that belongs to the Nuxt App)
</NuxtLink>
<a href="https://nuxtjs.org">External Link to another page</a>
</div>
</template>
```

```html{}[pages/parent.vue]
<template>
<div>
<h1>parent.vue</h1>
<NuxtChild />
</div>
</template>
::alert{type="info"}
If you want to know more about `<RouterLink>`, read theย [Vue Router documentation](https://next.router.vuejs.org/api/#router-link)ย for more information.
::

<!-- output -->
<template>
<div>
<h1>parent.vue</h1>
<div>
<h3>child.vue</h3>
</div>
</div>
</template>
## Nested Routes

We provide a semantic alias for `RouterView`, the `<NuxtChild>` component, for displaying the children components of a [nested route](https://next.router.vuejs.org/guide/essentials/nested-routes.html).

Example:

```bash
-| pages/
---| parent/
------| child.vue
---| parent.vue
```

The example file tree above should generate these routes:
This file tree will generate these routes:

```js
[
Expand All @@ -106,3 +107,14 @@ The example file tree above should generate these routes:
}
]
```

To display theย `child.vue`ย component, you have to insert theย `<NuxtChild>` componentย insideย `pages/parent.vue`:

```html{}[pages/parent.vue]
<template>
<div>
<h1>I am the parent view</h1>
<NuxtChild :foobar="123" />
</div>
</template>
```
8 changes: 4 additions & 4 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10253,10 +10253,10 @@ std-env@^2.2.1, std-env@^2.3.0, std-env@^2.3.1:
dependencies:
ci-info "^3.1.1"

std-env@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/std-env/-/std-env-3.0.0.tgz#8dbd16bd2aadc18992072e2f5839e897f4ee2733"
integrity sha512-GoFEqAGzhaexp/T01rIiLOK9LHa6HmVwEUyeU4cwdSnOhfxpw9IMeAFi44SHWbCErEs29qEh7vAOUbtUmoycjA==
std-env@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/std-env/-/std-env-3.0.1.tgz#bc4cbc0e438610197e34c2d79c3df30b491f5182"
integrity sha512-mC1Ps9l77/97qeOZc+HrOL7TIaOboHqMZ24dGVQrlxFcpPpfCHpH+qfUT7Dz+6mlG8+JPA1KfBQo19iC/+Ngcw==

stream-browserify@^2.0.1:
version "2.0.2"
Expand Down