Comments (14)
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.
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.
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.
sure, looking forward to the example. Many thanks!
from nuxt.js.
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.
@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.
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.
It is indeed the case with nuxt-children-routes
😄
from nuxt.js.
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.
Hi @beeplin
You can now create children routes with the version 0.9.0
of Nuxt.js
from nuxt.js.
cool!
from nuxt.js.
@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.
Ahh.. I should use <nuxt-child/>
instead.
from nuxt.js.
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)
- Can't serve app under subfolder HOT 2
- definePageMeta not working while extendPages from *.js files HOT 2
- Netlify infinite 302 loop with query params & trailing slashes HOT 1
- Layers: Server middlewares are no longer ordered by filename HOT 2
- 'chokidar-granular' doesn't roload Nuxt while using NuxtKit/addLayout HOT 2
- app.cdnURL not applied to URLs in global CSS files HOT 1
- The document occurs error HOT 1
- `defineVitestConfig` from `@nuxt/test-utils` is not a drop-in replacement for `defineConfig` from `vite` (`No test suite found in file`) HOT 1
- During the localization process of Nuxt3, there was an issue of absolute referencing HOT 1
- ERROR input.replace is not a function HOT 2
- Wrong route handler used/RouteParams lost HOT 8
- Warning: "[Violation] Avoid using document.write()." HOT 1
- this is a bug report HOT 1
- Use html-minifier-terser instead of html-minifier for @nuxt/generator HOT 2
- Response status code is returned as 200 on a 404 page HOT 3
- There’s a bug HOT 1
- auto custom mode for ssr or csr HOT 1
- Can't auto import component as Pascal Case when use script lang="tsx" in SFC HOT 5
- Typescript not picking up extended NuxtConfig interface when installing with pnpm HOT 3
- Router params 'undefined' in server middleware HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.js.