Looking for input on a better approach to implement this feature. If you have any suggestions, feel free to share them.
I am working on creating a system with multiple inboxes where users can group their emails in different categories.
For instance, http://localhost/inbox/personal/
will display emails in the personal
inbox, while
http://localhost/inbox/business/3
will show emails in the business
inbox and highlight the email with the ID: 3
The routes are structured like this:
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'personal' // redirect to personal inbox
},
{
path: ':inbox',
component: InboxContentComponent, // list of emails in :inbox
children: [
{
path: '',
component: InboxNoSelectedEmailComponent, // no email selected
},
{
path: ':id',
component: InboxSelectedEmailComponent, // show selected email content
}
]
}
];
I am having difficulty with the InboxContentComponent
as I need to track changes in the inbox and whether an email is selected or not.
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.paramMap.subscribe(inbox => {
console.log('inbox', inbox);
});
}
Currently, events are only triggered when the inbox changes and not when the email changes. Is there a way to detect changes in the child route parameters?
Using
this.route.firstChild.paramMap.subscribe();
only works if the route has a first child during initialization. If the route is http://localhost/inbox/business/
, then this.route.firstChild
is null
One solution I considered is defining routes like this:
{
path: ':inbox/:id',
component: InboxContentComponent
}
and then checking in the InboxContentComponent
if :id
is set or not.
Any thoughts on this approach?