Skip to content

fix(router): restore internal URL on popstate when browserUrl is used#67557

Open
SkyZeroZx wants to merge 1 commit intoangular:mainfrom
SkyZeroZx:fix/router-browserurl-popstate
Open

fix(router): restore internal URL on popstate when browserUrl is used#67557
SkyZeroZx wants to merge 1 commit intoangular:mainfrom
SkyZeroZx:fix/router-browserurl-popstate

Conversation

@SkyZeroZx
Copy link
Contributor

@SkyZeroZx SkyZeroZx commented Mar 11, 2026

Fixed an issue where back/forward (popstate) navigation attempted to match the displayed browserUrl instead of the internal route, which could result in NG04002: Cannot match any routes.

Fixes #67549

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: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@pullapprove pullapprove bot requested a review from thePunderWoman March 11, 2026 05:11
@ngbot ngbot bot added this to the Backlog milestone Mar 11, 2026
})
class RootCmp {}

describe('browserUrl with popstate navigation', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering if we should put it in integration (I haven't found any tests related to browserUrl) or if it would be fine here, even though I use integration helpers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Putting this directly in packages/router/test/integration/integration.spec.ts seems good to me

@thePunderWoman thePunderWoman requested review from atscott and removed request for thePunderWoman March 11, 2026 15:24
} else {
const newState = {
...state,
...this.routerUrlState(navigation),
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in generateNgRouterState

: 'push';
const state = {
...transition.extras.state,
...this.routerUrlState(transition),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is now duplicated twice here. Let's make a similar generateNgRouterState like in history state manager

}
const rawUrl =
finalUrl !== undefined ? this.urlHandlingStrategy.merge(finalUrl!, initialUrl) : initialUrl;
return {ɵrouterUrl: this.urlSerializer.serialize(rawUrl)};
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe this is correct. The point of this is to preserve the internal URL used for matching routes. This is finalUrl only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

})
class RootCmp {}

describe('browserUrl with popstate navigation', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting this directly in packages/router/test/integration/integration.spec.ts seems good to me

const location = TestBed.inject(Location);
const router = TestBed.inject(Router);

await createRoot(router, RootCmp);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use RouterTestingHarness instead

Fixed an issue where back/forward (`popstate`) navigation attempted to match the displayed `browserUrl` instead of the internal route, which could result in `NG04002: Cannot match any routes`.

Fixes angular#67549
@SkyZeroZx SkyZeroZx force-pushed the fix/router-browserurl-popstate branch from 066ae0a to 0a0c674 Compare March 11, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BrowserUrl not working with popstate events

2 participants