I have a component that dynamically renders data based on the URL '/lp/:pageId'. The :pageId parameter is used to fetch data from the server in the ngOnInit()
lifecycle hook.
ngOnInit(){
this.apiHelper.getData(this.route.snapshot.params.pageId);
}
The problem I am encountering is ->
- When I navigate to
/lp/apple
, it successfully fetches and displays apple-related data. - However, when I'm already on
/lp/apple
and click a link to/lp/banana
, the route changes but no new data is fetched because the component is already loaded.
I attempted to fetch data whenever the route changes, but this caused issues with existing functionality.
If anyone has suggestions for best Angular practices to resolve this issue, I would greatly appreciate it. Thank you.