Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nuxt-child doesn't render the parent component

My folder structure is like this:

|-profile
|-- index.vue
|-- address/index.vue

And then I do <nuxt-child /> which doesn't render the content of profile/index.vue! It just loads a whole new route. Please help!

like image 356
Damon Avatar asked Nov 12 '18 15:11

Damon


People also ask

How to use nuxt child component to create parent and Child pages?

How to use the Nuxt Child component to create parent and child pages. pages/parent.vue contains the <NuxtChild> component. Everything on this page will be seen on both the parent and child pages. pages/parent/index.vue contains text that will be replaced when the child links are clicked.

How to display the children components in a nested route?

This component is used for displaying the children components in a nested route. To display the child.vue component, we have to insert <nuxt-child/> inside pages/parent.vue: Child components can also receive properties like a regular Vue component. To see an example, take a look at the nested-routes example.

How to display the child component of a Vue component?

To display the child.vue component, we have to insert <nuxt-child/> inside pages/parent.vue: Child components can also receive properties like a regular Vue component. To see an example, take a look at the nested-routes example.

How do I use keep-alive on <nuxt-child>?

When using keep-alive on <nuxt-child/>, the children components will register two additional lifecycle hooks: activated and deactivated . These hooks are called on the client side when entering and leaving the child component. To see an example, take a look at the named-views example.


1 Answers

Folder structure above will create a whole new route, instead of a nested one.

You can see exact same structure in Nuxt.js Routing documentation example.

Examples of nested routes are also available in documentation

In your case, in order to render nested route in <nuxt-child>, following structure will work:

|-pages/
|--| profile/
|-----| address.vue
|-----| index.vue
|--| profile.vue

And <nuxt-child> tag should be inside profile.vue page. This way profile/index.vue will be rendered when user navigates to /profile and address.vue will be rendered when user navigates to /profile/address.

like image 186
aBiscuit Avatar answered Oct 20 '22 01:10

aBiscuit