I'm not sure if this is the best way to implement this. If you have other opinions please share.
I have to implement a multi inbox system where the user can have multiple emails grouped by different inboxes.
For example: http://localhost/inbox/personal/
will show a list of emails in personal
inbox, http://localhost/inbox/business/3
will show a list of emails in business
inbox and will highlight email with id: 3
Routes look 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
}
]
}
];
My problem is with InboxContentComponent
. I need to detect when inbox changes and if an email is selected or not
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.paramMap.subscribe(inbox => {
console.log('inbox', inbox);
});
}
Events are emitted only when inbox changes and not when email changes. Is there a way to detect when child route parameters changes?
Doing this this.route.firstChild.paramMap.subscribe();
only works if on component initialization the route has a first child. if the route is like this http://localhost/inbox/business/
then this.route.firstChild
is null
On solution I could think is to define routes like this
{
path: ':inbox/:id',
component: InboxContentComponent
}
and then check in InboxContentComponent
if :id
is set or not
Any ideas?