Consider this scenario:
Upon navigating to the URL /product/123, the goal is to display the ProductComponent.
This is how it's currently configured:
RouterModule.forRoot([
{
path: 'product/:productId',
component: ProductComponent
},
{
path: '**', component: NotFoundComponent
},
]),
Recently, a resolver has been incorporated to verify the existence of the product ID. The updated setup appears as follows:
RouterModule.forRoot([
{
path: 'product/:productId',
component: ProductComponent,
resolver: {
productResolver: ProductResolver
}
},
{
path: '**', component: NotFoundComponent
},
]),
The resolver conducts an API call to confirm the existence of the productId parameter. However, if the productId is not found, the preference is to load the NotFoundComponent instead of redirecting to a different page (without altering the URL, contrary to Angular 2 documentation).
Does anyone have insights on achieving this? How can we have the NotFoundComponent loaded without changing the URL or engaging in navigation when the productId is not located via the resolver?