const routes: Routes = [ { path: '', redirectTo: '/home', pathMatch: ' full ' }, { path: 'home', component: HomeComponent }, { path: 'product/:id', component: ProductComponent, children: [ { path: '', component: ProductDescComponent }, { path: 'seller/:id', component: SellerInfoComponent } ] } , { path: '**', component: Code404Component } ];
<p> product works! </p> <p>商品Id{{productId}}</p> <a [routerLink]= " ['./'] " >Description</a> <a [routerLink]= " ['./seller',99] "> Seller Information</a> <router-outlet></router-outlet>
import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-seller-info', templateUrl: './seller-info.component.html', styleUrls: ['./seller-info.component.css'] }) export class SellerInfoComponent implements OnInit { private sellerId: number; constructor(private routeInfo: ActivatedRoute) { } by OnInit () { this.sellerId = this.routeInfo.snapshot.params["id"]; } } <p> SellerId is: {{sellerId}} </p>
<p>
Cow X Commodities
</p>