I used the following routing to return the detailPage of each product <a [routerLink]="['/shop-left-two/', tempProduct?.id]">
I got this error Failed to load resource: the server responded with a status of 500 ()
and my localhost@ http://localhost:4200/shop-left-two/undefined
ps : when I enter http://localhost:4200/shop-left-two/1 it works fine and returns the productDetails of the productid=1
shoplefttwo.component.html
<div class="col-lg-4 col-md-6" *ngFor="let tempProduct of products ">
<div class="food-box shop-box style-2">
<div class="thumb">
<a [routerLink]="['/shop-left-two/', tempProduct?.id]">
<img src="{{tempProduct.imageUrl}}" alt="images">
</a>
</div>
</div>
</div>
shopdetail.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Product } from 'src/app/common/product';
import { ProductService } from 'src/app/services/product.service';
import { RouterModule } from '@angular/router';
@Component({
selector: 'app-shopdetail',
templateUrl: './shopdetail.component.html',
styleUrls: ['./shopdetail.component.css']
})
export class ShopdetailComponent implements OnInit {
product:Product= new Product();
constructor(private productService: ProductService ,
private route:ActivatedRoute ) { }
ngOnInit(): void {
this.route.paramMap.subscribe( () =>{
this.handleProductDetails();
})
}
handleProductDetails() {
const theProductId:number = +this.route.snapshot.paramMap.get('id');
this.productService.getProduct(theProductId).subscribe(
data =>{
this.product= data ;
}
)
}
app-routing.module.ts
{path :'shop-left-two/:id' ,component:ShopdetailComponent ,data: { breadcrumb: 'Shop Detail' }}