At the moment, I currently have these route configurations:
{ path: '/:username', component: Profile, children: [
{ path: '', component: Map , name: 'Profile'},
{ path: 'locations', component: Locations, name: 'Locations'},
{ path: 'map', component: Map, name: 'Map'}
]},
My goal is to create a markers: []
array that will be populated from my database when the mounted()
lifecycle hook executes. This array will then be used in both the Map
and Locations
components.
I'm contemplating on the best approach to achieve this. Here are my options:
- Include the
markers: []
property along with themounted()
hook in the local state of each component, resulting in two separate axios calls in each component. - Add the
markers: []
property and themounted()
hook to the main parent component of the nested routes, and then pass down the data as props to each component. This method only requires one axios call, but it raises concerns about passing data down through props if the nested components are not direct children of the parent element.
Considering the second scenario, I am uncertain if passing data down as props would work since the nested components may not directly be children of the parent element.