Timothy
Timothy

Reputation: 3593

Angular wildcard to match child routes

Trying to find subroutes with a component

const routes: Routes = [
  {
    path: '',
    component: CatalogueComponent,
  },
  {
    path: 'search/**',
    component: CatalogueComponent,
  },
  ...
  {
     path: '**',
     redirectTo: '/page-not-found'
  }
}

Just can't get it work. path: 'search/',** is never matched..

search url is as follows: search/brand=sdfsdf/model=sdfvsdf/page=2

Upvotes: 0

Views: 174

Answers (1)

Guerric P
Guerric P

Reputation: 31815

You shouldn't be using URLs like you mentioned, the right pattern to use is search?brand=sdfsdf&model=sdfvsdf&page=2 and then retrieve the query params by injecting ActivatedRoute into the CatalogueComponent, with either this.activatedRoute.snapshot.queryParams or this.activatedRoute.queryParams.subscribe(params => ...) if you want to react to the params change which I think is what you need.

Upvotes: 2

Related Questions