Sitelet https://web.archive.org/web/20211120120948/https://github.com/angular/angular/pull/43087
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(router): null/undefined routerLink should disable navigation #43087

Closed
wants to merge 1 commit into from

Conversation

@atscott
Copy link
Contributor

@atscott atscott commented Aug 9, 2021 •

The current behavior of routerLink for null and undefined inputs is to treat
the input the same as []. This creates several unresolvable issues with
correctly disabling the links because commands = [] does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the routerLink input will be to completely disable navigation
for null and undefined inputs. For HTML Anchor elements, this will also mean
removing the href attribute.

Fixes #21457
Fixes #13980
Fixes #31154

BREAKING CHANGE:
Previously null and undefined inputs for routerLink were
equaivalent to empty string and there was no way to disable the link's
navigation.
In addition, the href is changed from a property HostBinding() to an
attribute binding (HostBinding('attr.href')). The effect of this
change is that DebugElement.properties['href'] will now return the
href value returned by the native element which will be the full URL
rather than the internal value of the RouterLink href property.

@ngbot ngbot bot added this to the Backlog milestone Aug 9, 2021
@ngbot ngbot bot added this to the Backlog milestone Aug 9, 2021
@google-cla google-cla bot added the cla: yes label Aug 9, 2021
@atscott
Copy link
Contributor Author

@atscott atscott commented Aug 9, 2021

global presubmit has failures that need to be resolved.

Loading

@atscott atscott force-pushed the routerlinknull branch 2 times, most recently from 060a3de to 5901045 Aug 9, 2021
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

LGTM 🍪

Just one suggestion, but otherwise 👍🏻 .

reviewed-for: public-api

Loading

packages/router/src/directives/router_link.ts Outdated Show resolved Hide resolved
Loading
@pullapprove pullapprove bot requested a review from petebacondarwin Aug 9, 2021
@atscott atscott force-pushed the routerlinknull branch from 5901045 to 1fd01d8 Aug 9, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

LGTM 👍 Just a few minor comments.

Loading

packages/router/src/directives/router_link.ts Outdated Show resolved Hide resolved
Loading
packages/router/src/directives/router_link.ts Outdated Show resolved Hide resolved
Loading
packages/router/src/directives/router_link.ts Show resolved Hide resolved
Loading
packages/router/src/directives/router_link.ts Outdated Show resolved Hide resolved
Loading
@pullapprove pullapprove bot requested review from jelbourn Aug 9, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Reviewed-for: public-api

Loading

@atscott atscott force-pushed the routerlinknull branch 2 times, most recently from ebb1e1c to ac7308e Aug 9, 2021
The current behavior of `routerLink` for `null` and `undefined` inputs is to treat
the input the same as `[]`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does _not_ behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Fixes angular#21457
Fixes angular#13980
Fixes angular#31154

BREAKING CHANGE:
Previously `null` and `undefined` inputs for `routerLink` were
equaivalent to empty string and there was no way to disable the link's
navigation.
In addition, the `href` is changed from a property `HostBinding()` to an
attribute binding (`HostBinding('attr.href')`). The effect of this
change is that `DebugElement.properties['href']` will now return the
`href` value returned by the native element which will be the full URL
rather than the internal value of the `RouterLink` `href` property.
@atscott atscott force-pushed the routerlinknull branch from 67f7513 to 752f3eb Aug 11, 2021
@atscott
Copy link
Contributor Author

@atscott atscott commented Aug 11, 2021

started another global presubmit train after some g3 cleanup

Loading

atscott added a commit to atscott/angular that referenced this issue Aug 16, 2021
The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in angular#43087
atscott added a commit to atscott/angular that referenced this issue Aug 16, 2021
The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in angular#43087
atscott added a commit to atscott/angular that referenced this issue Aug 16, 2021
The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in angular#43087
atscott added a commit to atscott/angular that referenced this issue Aug 16, 2021
The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in angular#43087
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Reviewed-for: public-api

Did you consider an automated migration for this breaking change?

Loading

@atscott
Copy link
Contributor Author

@atscott atscott commented Aug 17, 2021

@petebacondarwin - I did. #43176 identifies and produces a warning for routerLink=“”.
An ideal migration would be to identify nullable inputs as well and add ?? [] but that would require template type information that we don’t have in migrations, AFAIK.

Loading

atscott added a commit to atscott/angular that referenced this issue Aug 17, 2021
The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in angular#43087
atscott added a commit to atscott/angular that referenced this issue Aug 17, 2021
The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in angular#43087
atscott added a commit to atscott/angular that referenced this issue Aug 18, 2021
The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in angular#43087
@atscott
Copy link
Contributor Author

@atscott atscott commented Aug 18, 2021

After more migrations, started another global presubmit

Loading

@atscott
Copy link
Contributor Author

@atscott atscott commented Aug 19, 2021

Loading

@atscott
Copy link
Contributor Author

@atscott atscott commented Aug 19, 2021

caretaker note: please merge and sync on its own. I've done many rounds of g3 migrations and global TAP is green, but I still think it's likely there will be failures. It would be good to have this as the only item in the sync so the breaking changes notes are easy to find and resolve.

Loading

alxhub added a commit that referenced this issue Aug 19, 2021
…43176)

The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in #43087

PR Close #43176
alxhub
alxhub approved these changes Aug 20, 2021
@alxhub alxhub closed this in ccb09b4 Aug 20, 2021
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 16, 2021
…ngular#43176)

The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in angular#43087

PR Close angular#43176
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 16, 2021
…ular#43087)

The current behavior of `routerLink` for `null` and `undefined` inputs is to treat
the input the same as `[]`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does _not_ behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Fixes angular#21457
Fixes angular#13980
Fixes angular#31154

BREAKING CHANGE:
Previously `null` and `undefined` inputs for `routerLink` were
equaivalent to empty string and there was no way to disable the link's
navigation.
In addition, the `href` is changed from a property `HostBinding()` to an
attribute binding (`HostBinding('attr.href')`). The effect of this
change is that `DebugElement.properties['href']` will now return the
`href` value returned by the native element which will be the full URL
rather than the internal value of the `RouterLink` `href` property.

PR Close angular#43087
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 20, 2021

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.

Loading

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 20, 2021
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 22, 2021
…ular#43087)

The current behavior of `routerLink` for `null` and `undefined` inputs is to treat
the input the same as `[]`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does _not_ behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Fixes angular#21457
Fixes angular#13980
Fixes angular#31154

BREAKING CHANGE:
Previously `null` and `undefined` inputs for `routerLink` were
equaivalent to empty string and there was no way to disable the link's
navigation.
In addition, the `href` is changed from a property `HostBinding()` to an
attribute binding (`HostBinding('attr.href')`). The effect of this
change is that `DebugElement.properties['href']` will now return the
`href` value returned by the native element which will be the full URL
rather than the internal value of the `RouterLink` `href` property.

PR Close angular#43087
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.