私はangular2ルータを実装しようとしています。 '/ detail /:index'のようなURLパターンを使って ':detail/1234'のようなものを渡しています。 "someDomain/detail /%3AitemIndex; itemIndex = 123"と表示されます。これは "/ detail /:itemIndex; itemIndex = 123"を意味します。どのようにこれを修正し、 "/ detail/123" OR "/ detail/itemIndex = 123"と期待される結果を取得し、 ":itemIndex;"そして、(私のタイプミスを無視してください)不正確なURLを返すAnguar2 routerLink
が
export const rootRouterConfig: Routes = [
{ path: '', redirectTo: 'SomeHomeComponent', pathMatch: 'full' },
{ path: 'home', component: SomeHomeComponent },
{ path: 'detail/:itemIndex', component: SomeDetailComponent }];
"list.component.html"
<a *ngFor="let item of items; let i = index"
[routerLink]="['/detail/:itemIndex', { itemIndex: i }]">
{ item.name }
</a>
"SomeDetail.Component.tsを" "app.routes.ts" スラッシュでそれを置き換えます
import { ActivatedRoute } from '@angular/router';
export class SomeDetailComponent {
private itemIndex:string;
constructor(private route: ActivatedRoute){
}
ngOnInit() {
this.route.params.subscribe(params => { this.itemIndex = params['itemIndex'];
});
}
}