Skip to content

Conversation

@portneon
Copy link
Contributor

@portneon portneon commented Nov 15, 2025

Update the code sample to use event.code instead of event.reason for cancellation checks, while preserving event.reason in the console.warn line. This aligns the example with the NavigationCancellationCode enum and prevents confusion.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • 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.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #65182

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

The previous example incorrectly compared event.code. Updated to use event.reason
to match the current NavigationCancel API. This fixes the type errors that were
caused by the old example.

Closes #65232
Closes #65235

@pullapprove pullapprove bot requested a review from crisbeto November 15, 2025 21:04
@angular-robot angular-robot bot added area: docs Related to the documentation area: router labels Nov 15, 2025
@ngbot ngbot bot added this to the Backlog milestone Nov 15, 2025
} else if (event instanceof NavigationCancel) {
console.warn('Navigation cancelled:', event.reason);
if (event.reason === NavigationCancellationCode.GuardRejected) {
console.warn('Navigation cancelled:', event.code);
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to what was mentioned earlier, I think event.reason should be preserved for the example on line 179

Copy link
Contributor

@SkyZeroZx SkyZeroZx Nov 15, 2025

Choose a reason for hiding this comment

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

On the other hand, you can amend the commit so it links correctly to the issue
See Commit Message Footer

Copy link
Contributor Author

@portneon portneon Nov 15, 2025

Choose a reason for hiding this comment

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

I have updated the line that i forgot to update when i was recreating the pr also now i have mentioned my two old pr which i closed and raised a new one.Please do consider this one.And sorry for the mistakes i have made.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can merge both commits into one.

Copy link
Contributor Author

@portneon portneon Nov 15, 2025

Choose a reason for hiding this comment

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

Yes I have merged both the pr in this one and created a new pr also I closed both my old pr I just mentioned that my previous pr refers to same issue so you can connect with this pr

Copy link
Contributor

Choose a reason for hiding this comment

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

You should keep this as a single commit rather than the two separate commits currently shown.In the tab Commits

Please squash your changes into one commit before submitting.

@portneon portneon force-pushed the fix/cla-single-commit branch from b58def4 to 8b4ce3d Compare November 16, 2025 03:55
The example was comparing  (string) against  enum,
causing a TypeScript type error (TS2367). Also, the import  from
 was missing.

This change updates the example to use , ensuring type compatibility
and adding the missing import.

See: https://next.angular.dev/guide/routing/lifecycle-and-events#error-handling
@portneon portneon force-pushed the fix/cla-single-commit branch from 8b4ce3d to 78c406d Compare November 16, 2025 04:43
@portneon portneon closed this Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: docs Related to the documentation area: router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants