Visitar URL original
fix(router): preserve replaceUrl when returning a urlTree from CanAct… by blathers16 · Pull Request #54042 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20240524040916/https://github.com/angular/angular/pull/54042
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): preserve replaceUrl when returning a urlTree from CanAct… #54042

Conversation

blathers16
Copy link
Contributor

…ivate

This commit will fix the issue of the setting of NavigationExtras.replaceUrl being lost when returning a urlTree from a CanActivateFn.

Fixes #53503

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • [ X] Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

#53503
Issue Number: 53503

What is the new behavior?

NavigationExtras.replaceUrl is preserved.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2024
@JeanMeche JeanMeche added the target: major This PR is targeted for the next major release label Jan 23, 2024
@AndrewKushnir AndrewKushnir removed their request for review January 24, 2024 01:33
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: docs Related to the documentation area: build & ci Related the build and CI infrastructure of the project labels Feb 3, 2024
@blathers16
Copy link
Contributor Author

Hi @atscott I have updated the pull request as well as added extra tests to confirm that your above suggestion is working.

@JeanMeche
Copy link
Member

@blathers16 It looks like something went wrong during rebase. Your PR includes 167 commits, can you have a look ? thank you.

@blathers16
Copy link
Contributor Author

hi @JeanMeche that is probably because I didn't try to rebase. What is the goal here? To end up with a single commit for the entire PR?

@JeanMeche
Copy link
Member

JeanMeche commented Feb 3, 2024 •

Yes, the PR should include only the changes intended for the fix. Currently having 1,017 file changes makes it hard to review.
Also having a single commit allows easy reverts if the change introduces an unwanted breaking change.

@blathers16 blathers16 force-pushed the navigationurloptions-not-preserved-#53506 branch from d285510 to 3c857f3 Compare February 3, 2024 23:49
@angular-robot angular-robot bot removed detected: feature PR contains a feature commit area: docs Related to the documentation area: build & ci Related the build and CI infrastructure of the project labels Feb 3, 2024
@blathers16
Copy link
Contributor Author

Hi, @JeanMeche, I think I fixed it. I have no idea where the 1,017 files came from, all I did was merge in upstream/main. Anyways, it should be all in one commit with no unrelated changes now.

packages/router/src/router.ts Outdated Show resolved Hide resolved
packages/router/test/computed_state_restoration.spec.ts Outdated Show resolved Hide resolved
@blathers16 blathers16 force-pushed the navigationurloptions-not-preserved-#53506 branch from c7a0e23 to 1048a1c Compare February 7, 2024 01:03
@blathers16 blathers16 force-pushed the navigationurloptions-not-preserved-#53506 branch 2 times, most recently from 0daf811 to 973e9b6 Compare February 21, 2024 21:01
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's quite a lot of unused code here and tests that could be simplified by using newer features: standalone, functional guards, RouterTestingHarness, etc. Older tests in the router code unfortunately aren't good examples of how new ones should be written.

packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
packages/router/test/router_navigation_extras.spec.ts Outdated Show resolved Hide resolved
@blathers16 blathers16 force-pushed the navigationurloptions-not-preserved-#53506 branch 2 times, most recently from 9ba1b83 to 7cd0f71 Compare February 24, 2024 19:16
@blathers16
Copy link
Contributor Author

Hi, @atscott, I made most of the requested changes except using RouterTestingHarness. It doesn't seem to have a way to pass NavigationExtras, so I don't think it can be used in this case. Feel free to correct me if I am wrong.

@blathers16 blathers16 force-pushed the navigationurloptions-not-preserved-#53506 branch from 7cd0f71 to 3841e7d Compare February 24, 2024 19:46
@atscott atscott force-pushed the navigationurloptions-not-preserved-#53506 branch from 65fc0fd to 531414d Compare March 26, 2024 19:33
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Mar 26, 2024
…ivate

This commit will fix the issue of the setting of NavigationExtras.replaceUrl being lost when
returning a urlTree from a CanActivateFn.

Fixes angular#53503

BREAKING CHANGE: When a a guard returns a `UrlTree` as a redirect, the
redirecting navigation will now use `replaceUrl` if the initial
navigation was also using the `replaceUrl` option. If this is not
desirable, the redirect can configure new `NavigationBehaviorOptions` by
returning a `RedirectCommand` with the desired options instead of `UrlTree`.
@atscott atscott force-pushed the navigationurloptions-not-preserved-#53506 branch from 531414d to 4701889 Compare March 26, 2024 19:34
@atscott atscott added the requires: TGP This PR requires a passing TGP before merging is allowed label Mar 26, 2024
@atscott
Copy link
Contributor

atscott commented Mar 27, 2024

green TGP

@atscott atscott added the action: merge The PR is ready for merge by the caretaker label Mar 27, 2024
@dylhunn dylhunn added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Mar 27, 2024
@dylhunn
Copy link
Contributor

dylhunn commented Mar 27, 2024

caretaker: this change has a green TGP above

@dylhunn
Copy link
Contributor

dylhunn commented Mar 27, 2024

This PR was merged into the repository by commit 60f1d68.

@dylhunn dylhunn closed this in 60f1d68 Mar 27, 2024
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
…ivate (angular#54042)

This commit will fix the issue of the setting of NavigationExtras.replaceUrl being lost when
returning a urlTree from a CanActivateFn.

Fixes angular#53503

BREAKING CHANGE: When a a guard returns a `UrlTree` as a redirect, the
redirecting navigation will now use `replaceUrl` if the initial
navigation was also using the `replaceUrl` option. If this is not
desirable, the redirect can configure new `NavigationBehaviorOptions` by
returning a `RedirectCommand` with the desired options instead of `UrlTree`.

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

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 27, 2024
@pullapprove pullapprove bot removed the requires: TGP This PR requires a passing TGP before merging is allowed label Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: router breaking changes detected: breaking change PR contains a commit with a breaking change merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replaceUrl not preserved in redirect
4 participants