This repository was archived by the owner on Dec 4, 2017. It is now read-only.
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
ToH should use anchors + routerLink instead of router.navigate almost everywhere #998
Closed
Description
For example in https://angular.io/docs/ts/latest/tutorial/toh-pt5.html
The example code right now looks like this:
<div *ngFor="#hero of heroes" (click)="gotoDetail(hero)" class="col-1-4">
gotoDetail(hero: Hero) {
let link = ['HeroDetail', { id: hero.id }];
this._router.navigate(link);
}
This code is problematic because of the following reasons:
- the navigation via the div is not accessible (to screenreaders and users using keyboard for navigation)
- it's not possible to left-click+cmd to open the link in a new tab/window
- it's not possible to right-click on an item and copy the link
- SEO also suffers because crawlers don't see a link so they can't index the transition to the new state
All these problems can be avoided (and the code can be made shorter) if routerLink
directive is used instead:
<a *ngFor="#hero of heroes" [routerLink]="['HeroDetail', { id: hero.id }]" class="col-1-4">
This code will generate a link that has all the good properties listed above, while fully preserving the functionality of the app.
Metadata
Metadata
Assignees
Labels
No labels