如何在 angular 的路由中使用参数?
How to use parameters in routes with angular?
我正在尝试通过 ts 代码使用路由,但我在使用参数时遇到问题。
onSubmit(s) {
this.router.navigate(['/search', {string: 'mulher'} ]) ;
}
路线
export const ROUTES: Routes = [
{path: '', component: AppComponent,
children: [
{ path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: 'home', component: HomeComponent },
{ path: 'categoria/:id', component: ListaComponent },
{ path: 'player/:id', component: PlayerComponent },
{ path: 'search/:string', component: SearchComponent }]
}]
core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: Cannot
match any routes. URL Segment: 'search;string=mulher' Error: Cannot
match any routes. URL Segment: 'search;string=mulher'
您可以简单地使用:
this.router.navigate(['/search', 'mulher']);
我正在尝试通过 ts 代码使用路由,但我在使用参数时遇到问题。
onSubmit(s) {
this.router.navigate(['/search', {string: 'mulher'} ]) ;
}
路线
export const ROUTES: Routes = [
{path: '', component: AppComponent,
children: [
{ path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: 'home', component: HomeComponent },
{ path: 'categoria/:id', component: ListaComponent },
{ path: 'player/:id', component: PlayerComponent },
{ path: 'search/:string', component: SearchComponent }]
}]
core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'search;string=mulher' Error: Cannot match any routes. URL Segment: 'search;string=mulher'
您可以简单地使用:
this.router.navigate(['/search', 'mulher']);