BETTERZON-41: Added routing for product detail pages

This commit is contained in:
Patrick Müller 2020-12-03 11:31:48 +01:00
parent 38b20d28cb
commit 87193310a8
3 changed files with 15 additions and 9 deletions

View File

@ -8,7 +8,7 @@ import {ProductDetailPageComponent} from './product-detail-page/product-detail-p
const routes: Routes = [ const routes: Routes = [
{path: '', component: LandingpageComponent}, {path: '', component: LandingpageComponent},
{path: 'product', component: ProductDetailPageComponent} {path: 'product/:id', component: ProductDetailPageComponent}
]; ];
@NgModule({ @NgModule({

View File

@ -1 +1 @@
<p>product-detail-page works!</p> <p>product-detail-page works! Product: {{productId}}</p>

View File

@ -1,15 +1,21 @@
import { Component, OnInit } from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
@Component({ @Component({
selector: 'app-product-detail-page', selector: 'app-product-detail-page',
templateUrl: './product-detail-page.component.html', templateUrl: './product-detail-page.component.html',
styleUrls: ['./product-detail-page.component.css'] styleUrls: ['./product-detail-page.component.css']
}) })
export class ProductDetailPageComponent implements OnInit { export class ProductDetailPageComponent implements OnInit {
productId: string;
constructor() { } constructor(
private router: Router
) {
this.productId = router.url.substr(9, router.url.length);
}
ngOnInit(): void { ngOnInit(): void {
} }
} }