I have a parent component which passes data down to children through Input(). Before the last refactoring it worked fine. Now I have added two children routes to keep the navbar and sidemenu fixed and change the main content when the user click a menu item. Before refactoring the home path was "home" now it has two child routes: "/home/A" and "/home/B".
/home/A is what /home was before the refactoring and the path you get redirected to after login but now the A component's Input() does not get any value . Are Input()s meant to work in the scenario described above or there's another correct way to pass data from parent to children when children are on a child route?
#Component Input and children routes
5 messages · Page 1 of 1 (latest)
You should need to pass the data via the url. https://angular.io/guide/router-tutorial-toh#route-parameters
I find it quite odd to have to pass data though the router. The idea was to not couple the dumb component (B) to anything by getting the needed data through inputs but adding the Router dependency makes it not re-usable in the case I need to use it without children routes. If there's really to pass data from parent to child component when the latter is 'inside' a router outlet is really disappointing.
You could also use a service that contains the state. Or you could have a container component that passes the data that it gets from somewhere to the dumb child.
Hi @fiery eagle , I agree with @naive umbra. I think if you have data that needs sharing across multiple components and routes it would make sense to store this data in some sort of state whether that be an NgRX store or a BehaviourSubject in a common/shared service.