0

Routing issue when i try with "http://localhost:4200/Search-result" but its not redirect. Can you please say me what is wrong with it? Its Redirect to Home page path.

 { path: '', component: HomeComponent, pathMatch: 'full' },
 {
    path: 'search-result',
    pathMatch: 'full',
    component: SearchResultComponent
  },
  {
    path: 'search-result/:searchText',
    pathMatch: 'full',
    component: SearchResultComponent
  }
Urvish Patel
  • 134
  • 15

1 Answers1

0

https://angular.io/api/router/Routes

You are using pathMatch: 'full' which means, that the whole URL path needs to match and is consumed by the route matching algorithm.

and in your URL 'http://localhost:4200/Search-result' ":searchText" is not passed. Henceforth it is redirecting to default route.

Note there is one more possible value for pathMatch: pathMatch: 'prefix' means, the first route where the path matches the start of the URL is choosen, but then the route matching algorithm is continuing searching for matching child routes where the rest of the URL matches

Charu Maheshwari
  • 1,583
  • 1
  • 8
  • 9
  • but I was create another routes for searchText. see this link https://stackoverflow.com/questions/34208745/angular-2-optional-route-parameter another link for same https://elanderson.net/2017/01/angular-2-optional-route-parameter/ – Urvish Patel Jun 26 '18 at 05:11
  • And i was remove pathMatch: 'full' and check it but it didn't work for me – Urvish Patel Jun 26 '18 at 05:12
  • Can you try using 'http://localhost:4200/search-result' ". "S" is capital in "search-result". Try changing it to lowercase. – Charu Maheshwari Jun 26 '18 at 05:33