-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Allow nested routes without parent component #2105
Comments
If you need nested path the recommended approach is to use a function to generate the routes with the prefix: function prefixRoutes(prefix, routes) {
return routes.map(route => route.path = prefix + '/' + route.path)
}
new Router({
routes: [
// some routes
...prefixRoutes('/prefix', [
{ path: 'one', component: ... },
{ path: 'two', component: ... },
])
]
}) |
I hacked around this with a component named <!-- PassThrough.vue -->
<template>
<router-view />
</template> // router.js
new Router({routes: [{
path: '/prefix',
component: PassThrough,
children: [
{ path: 'one', component: ... },
{ path: 'two', component: ... },
]
}]}) |
How should specify path to direct? Just specifying without prefix or with both is taking me to 404. |
This throw a error because inside the map you return only the path.
Example:
Routes return:
You can change the union with prefix inside the function ("") to ("/") if you not start the children paths with "/" |
Expanding on what @deckar01 proposed, we can do away with the redundant SFC 👇
|
Just hit this issue again. I keep on forgetting this one on new projects where it makes sense to "namespace" several pages... and then I wonder why things broke, as there's just a blank page without error messages. Then I re-read the docs, and read the thing with two It makes little sense to me that the child is not inserted into the main Also - hello, future me 👋 |
I'd also like to give this issue a "bump". Nested routes are particularly helpful for displaying a breadcrumb in my UI. Though the routes are nested, there's no point nesting components. For example, in my app the path It would be cleaner and less cumbersome if we didn't have to add a component to every route, and a child route was rendered in the component of it's closest ancestor with |
hi, @andreasvirkus. Do you know how to use it in next router of vue 3 ? |
I think you'd need to use
I haven't tested this through yet though. |
@andreasvirkus Thank you, It's all right! |
@carmel
|
@Jenesius While the above looks promising, I could not get it to work. |
What version of VUE u use? |
@azollai |
We have been using |
@dnikl: Did you ever find a solution for this? I have precisely the same use case |
@Soren-Knudsen unfortunately not. |
4 years later, I keep coming back to this issue... |
nested routes and nested names and meta group
you can call function like |
Anyone found a clean solution to get rid of this warning :
when using |
Any news on this about how to add nested routes without parent component? |
What problem does this feature solve?
Allows the routes to be defined with a prefix that doesn't need to be repeated in each route.
What does the proposed API look like?
Currently this doesn't work because the parent route doesn't have a component specified. This feature isn't about nested routes but just about nested paths.
Creates
/prefix/one
and/prefix/two
.The text was updated successfully, but these errors were encountered: