Giter Site home page Giter Site logo

routes don't support "children"? about nuxt.js HOT 14 CLOSED

nuxt avatar nuxt commented on April 28, 2024
routes don't support "children"?

from nuxt.js.

Comments (14)

Atinux avatar Atinux commented on April 28, 2024 8

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.

from nuxt.js.

beeplin avatar beeplin commented on April 28, 2024 1

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?

from nuxt.js.

Atinux avatar Atinux commented on April 28, 2024

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?

from nuxt.js.

beeplin avatar beeplin commented on April 28, 2024

sure, looking forward to the example. Many thanks!

from nuxt.js.

beeplin avatar beeplin commented on April 28, 2024

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 )

from nuxt.js.

Atinux avatar Atinux commented on April 28, 2024

@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.

from nuxt.js.

Atinux avatar Atinux commented on April 28, 2024

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?

from nuxt.js.

Atinux avatar Atinux commented on April 28, 2024

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

from nuxt.js.

beeplin avatar beeplin commented on April 28, 2024

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.

from nuxt.js.

Atinux avatar Atinux commented on April 28, 2024

Hi @beeplin

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

Explanations here

from nuxt.js.

beeplin avatar beeplin commented on April 28, 2024

cool!

from nuxt.js.

dotnetCarpenter avatar dotnetCarpenter commented on April 28, 2024

@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?

from nuxt.js.

dotnetCarpenter avatar dotnetCarpenter commented on April 28, 2024

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

from nuxt.js.

lock avatar lock commented on April 28, 2024

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.

from nuxt.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.