You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AddRoute() with ParentName does not add routes as Children of the parent
I came across this issue when I was trying to access children of a Route but kept getting undefined.
I am trying to get the router object with all the routes consisting or parents and child routes but Unflattened.
router.getRoutes() -> Flattened Array
I need to know which route is child and which is not. This functionality will improve the way we resolve routes and catch errors for 3rd party integration.
1 of the challenges I am facing is to be able to get the list of all the children of a parent route.
Code Structure:
const router = createRouter({
history: createWebHistory(),
routes: [{
path: "/home",
name: "home",
component: HomePageVue
}]
})
const sampleChildRoute = [{
path: "/sample",
name: "sample",
component: SamplePageVue
}]
// Adding routes to parent name = home
sampleChildRoute.forEach(route => router.addRoute( 'home', route ))
router.options.routes.forEach(route => console.log(route.children))
// This code works fine.
When I try to run a for loop to console.log(children of Home)
Its always undefined.
I know a very rough gist of what is wrong here but I would highly appreciate an explanation for this behaviour.
🥲🥲🥲🥲!!!
My Request
The above code add the route just fine but has implication on resolution of routes with scrutiny based architecture.
It would be great to see if we could add a way to differentiate weather 🌦️ a route is child or is parenting other routes.
This discussion was converted from issue #2246 on May 25, 2024 20:43.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What problem is this solving
AddRoute() with ParentName does not add routes as Children of the parent
I came across this issue when I was trying to access children of a Route but kept getting undefined.
I am trying to get the router object with all the routes consisting or parents and child routes but Unflattened.
router.getRoutes()
-> Flattened ArrayI need to know which route is child and which is not. This functionality will improve the way we resolve routes and catch errors for 3rd party integration.
1 of the challenges I am facing is to be able to get the list of all the children of a parent route.
Code Structure:
When I try to run a for loop to console.log(children of Home)
Its always undefined.
I know a very rough gist of what is wrong here but I would highly appreciate an explanation for this behaviour.
🥲🥲🥲🥲!!!
My Request
The above code add the route just fine but has implication on resolution of routes with scrutiny based architecture.
It would be great to see if we could add a way to differentiate weather 🌦️ a route is child or is parenting other routes.
Discussion History Reference
Related: #600
Proposed solution
I would like
router.addRoute( ParentName, childRoute )
to be accessible byparentRoute.children
Describe alternatives you've considered
An alternative is adding the updated parent route again.
Beta Was this translation helpful? Give feedback.
All reactions