Skip to content

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

Closed

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.

Activity

  1. added
    featureLabel used to distinguish feature request from other issues
    open for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).
    on Aug 9, 2022
  2. added this to the Backlog milestone on Aug 9, 2022
  3. angular-robot commented on Aug 10, 2022

    @angular-robot
    Contributor

    This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

    You can find more details about the feature request process in our documentation.

  4. angular-automatic-lock-bot commented on Sep 30, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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