I want to pass a parameter in my URL when a search button is clicked. I wanted it to look like this. /result?search=sap
However, I am getting this error in console. Error: Cannot match any routes. URL Segment: 'result;search=sap' I can't figure out what I'm doing wrong. Here is my code.
SearchComponent.ts
search(){
//this function is accessed when a user clicks on a search button in the HTML
this.router.navigate(['/result', { search: this.query }]);
//this.query = sap
}
AppModule.ts
const routes: Routes = [
//other routes here
{ path: 'result/:search', component: SearchComponent}
];
@NgModule({
declarations: [
//other components
SearchComponent
] ,
imports: [
//other modules
RouterModule.forRoot(routes, {}),
],