I have an Angular 5 app in which I need a URL to use the following form:
www.example.com/#/company/<companyId>/transactions
I am using a non-named router outlet <router-outlet></router-outlet>
The companyId is a parameter. Initially I left off the transactions portion in the router and verified that I can correctly reach the transactions page associated with the CompanyTransactionsComponent.
The router rule was:
www.example.com/#/company/<id>/
{ path: 'company/:companyId', component: CompanyTransactionsComponent }
this.router.navigateByUrl('/company/' + user.companyId);
which worked fine, but when I changed to add /transactions:
www.example.com/#/company/<id>/transactions/
{ path: 'company/:companyId/transactions', component: CompanyTransactionsComponent }
this.router.navigateByUrl('/company/' + user.companyId + '/transactions/');
This was giving me an error Cannot match any routes.
so I tried a couple other options below:
{
path: 'company/:companyId',
component: CompanyTransactionsComponent,
children: [
{
path: 'transactions',
component: CompanyTransactionsComponent
}
]
},
and:
RouterModule.forRoot([
{ path: 'company/:companyId', component: CompanyTransactionsComponent }
],
RouterModule.forChild([
{
path: 'company/:companyId',
children: [
{
path: 'transactions',
component: CompanyTransactionsComponent
}
]
},
])
Both give the same error. This seems to only happen because I use the /transactions after the parameter /:companyId. Any idea how I can accomplish having a sub-page following the parameter in the url?
EDIT CompanyTransactionsComponent is used for both parent and child because there is not yet a CompanyHomeComponent, so the transactions page will be the default page when no sub-page is entered. There are multiple children besides the CompanyTransactionsComponent I left out to keep the code shorter.