Different routes same component

后端 未结 4 1457
眼角桃花
眼角桃花 2021-01-01 12:06

I want to achieve something like this /products shows all the products and /products/:category shows all the products related to a specific categor

4条回答
  •  無奈伤痛
    2021-01-01 12:14

    you can solve it by adding routes

    const routes: Routes = [
        { path: 'experience',
            children: [
                { path: 'pending', component: ExperienceComponent },
                { path: 'requests', component: ExperienceComponent },
            ] }]
    

    and in ExperienceComponent import

    import { ActivatedRoute } from "@angular/router";
    

    and in constructor add this parameter

    constructor(public route: ActivatedRoute)
    

    and inside constructor get url

    this.route.url.subscribe(params => {
      console.log(params[0].path);
    })
    

提交回复
热议问题