Skip to content

feat(router): improve typings for RouterLink boolean inputs #47100

@EmmanuelRoux

Description

@EmmanuelRoux

Which @angular/* package(s) are relevant/related to the feature request?

router

Description

Boolean inputs of RouterLink (and RouterLinkWithHref) should also accept empty string '' (and coerce that value to true).

Actually, such inputs are already coerced to boolean when they are read. Instead, they should be coerced by a setter to allow simpler template bindings, such as <a routerLink="/" skipLocationChange> instead of <a routerLink="/" [skipLocationChange]="true">. Currently, a compile-time error is thrown with the former syntax.

These inputs are: preserveFragment, skipLocationChange and replaceUrl.

Proposed solution

Add getter/setter to preserveFragment, skipLocationChange and replaceUrl fields of RouterLink and RouterLinkWithHref directives, for example:

private _skipLocationChange: boolean = false;

get skipLocationChange(): boolean { return this._skipLocationChange; }

@Input() set skipLocationChange(skipLocationChange: boolean | '' | null | undefined) {
  this._skipLocationChange = coerceToBoolean(skipLocationChange);
}

Alternatives considered

No alternative, more verbose template syntax is required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerfeatureLabel used to distinguish feature request from other issuesopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions