routerLink support of null/undefined

I think it would be convenient to allow routerLink to support a case where the binding resolves to null, empty array or undefined. In that case I’d expect an <a> tag to be created without a href attribute (or empty). This is useful for cases where something should be a link only if isn’t the current item, or should be a link if some property is set, but keeping two different HTML structures and *ngIf seems overcomplicated.

I.e. something like this

<a [routerLink]="foo && ['Foo', {bar:foo}]">Here's my item</a>

…instead of today’s

<a *ngIf="foo" [routerLink]="['Foo', {bar:foo}]">Here's my item</a>
<a *ngIf="!foo">Here's my item</a>

I could make a PR if it’s not in the workings. What do you think?

1 possible answer(s) on “routerLink support of null/undefined

  1. Doesn’t the following work all right?

    <a [routerLink]="foo ? ['Foo', {bar:foo}] : []">Here's my item</a>