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

routes don't support "children"? #20

Closed
beeplin opened this issue Nov 29, 2016 · 14 comments
Closed

routes don't support "children"? #20

beeplin opened this issue Nov 29, 2016 · 14 comments
Assignees

Comments

@beeplin
Copy link

beeplin commented Nov 29, 2016

I am not sure if I understand it right:

not supporting "children" in routes means we cannot user <router-view> in vue components, and therefore means all vue files in /pages are parallel stand-alone pages and cannot be nested. Since theres is actually no "parent component" and "child component", we have no way to pass props and slots into a component in /pages. The only way to pass something in a component is via router params.

Is that correct?

This feature request is available on Nuxt.js community (#c16)
@Atinux
Copy link
Member

Atinux commented Nov 29, 2016

It is 100% correct.

Actually you can implement your own child views easily by watching on $route in the page component and using with the is property.

I can create and example if you want to see how to implement it?

@beeplin
Copy link
Author

beeplin commented Nov 29, 2016

sure, looking forward to the example. Many thanks!

@beeplin
Copy link
Author

beeplin commented Nov 29, 2016

looks like currently nuxt is mainly for building multiple-page apps? If we are building a single-page app but still want server rendered components according to the router url, I guess the most natual way is to support nested components (children and )

@Atinux
Copy link
Member

Atinux commented Nov 29, 2016

@beeplin please take a look at this demo: https://hyperdev.com/#!/project/nuxt-children-routes

Live demo: https://nuxt-children-routes.hyperdev.space/parent

I use <component :is="child"/> to handle the child component of the given route, I also added a custom route in nuxt.config.js to tell Nuxt.js to call the pages/index.vue component on the /parent/:component? route.

@Atinux
Copy link
Member

Atinux commented Nov 29, 2016

I am not sure to understand when you are talking about a single-page app, could you describe me what you mean by single-page app?

@beeplin
Copy link
Author

beeplin commented Nov 29, 2016

Sorry for the vagueness of the term 'single-page app'. Let me take your recent nuxt-children-routes as an example:

When we are at /parent and click a link to go to /parent/foo , a 'multiple-page app' would re-render both parent and foo on the server, and then transfer the whole new html page (including both parent and foo) to the browser to replace the whole old page. So if we look from the browser side, \parent and \parent\foo are two different pages served by the server.

But in a so-called single-page app, when going from \parent to \parent\foo, the parent component should be reused. Only the new component foo is created and rendered, and then inserted into its proper position in the existing page. So if we look from the browser, we don't see a brand new page loaded, but only see a part of the existing page inserted/patched/removed.

Which is the case in the actual nuxt-children-routes example?

@Atinux
Copy link
Member

Atinux commented Nov 29, 2016

It is indeed the case with nuxt-children-routes 😄

@Atinux Atinux closed this as completed Nov 29, 2016
@beeplin
Copy link
Author

beeplin commented Nov 29, 2016

You mean it's like 'single-page app'? That's wonderful~

If so, is it possible to support children in routes and < router-view> in template? Using :is="xxx" can handle simple cases, but when the router goes complicated, it would be terrible to manually parse the url and handle multiple layers of :is. It would be perfect if we could use vue-router in the same old way as if we were using client-side-rendering.

@Atinux Atinux reopened this Dec 1, 2016
@Atinux
Copy link
Member

Atinux commented Dec 1, 2016

I'm re-opening this issue to know what think the community about it.

We will need to find a way to create child route with the pages folder as well and not only in the nuxt.config.js configuration.

For example:

-| pages/
----| user/
-------| index.vue
-------| profile.vue
-------| settings.vue
----| user.vue

The rule will be:

If a folder has the same name of a page, all the pages inside this folder will be the page children

This would generate:

[
  {
    path: '/user',
    component: 'pages/user.vue',
    children: [
      { path: '', component: 'pages/user/index.vue' },
      { path: 'profile', component: 'pages/user/profile.vue' },
      { path: 'settings', component: 'pages/user/settings.vue' }
    ]
  }
]

And pages/user.vue will have to use <router-view></router-view> inside its template.

@Atinux Atinux added the feature label Dec 1, 2016
@Atinux Atinux added this to the 1.0 milestone Dec 12, 2016
@Atinux
Copy link
Member

Atinux commented Dec 19, 2016

Hi @beeplin

You can now create children routes with the version 0.9.0 of Nuxt.js

Explanations here

@Atinux Atinux closed this as completed Dec 19, 2016
@beeplin
Copy link
Author

beeplin commented Dec 19, 2016

cool!

@dotnetCarpenter
Copy link

@Atinux I still don't see how the _id.vue component is re-used. As far as I can tell the entire <div class="user"> is removed from DOM an re-inserted.

My use-case is that I have a <object> element and need to change the data attribute but I can't use a child-route as it is implemented today because it removes the element (vue.js should do a diff on the v-node and just update the data attribute) instead of just updating the data attribute.

Am I missing something from your example?

@dotnetCarpenter
Copy link

dotnetCarpenter commented Nov 1, 2017

Ahh.. I should use <nuxt-child/> instead.

@lock
Copy link

lock bot commented Nov 5, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 5, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants