Commit graph

35 commits

Author SHA1 Message Date
SkyZeroZx
580212c995 fix(router): restore internal URL on popstate when browserUrl is used
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

(cherry picked from commit 6eff439546)
2026-04-20 16:46:30 -07:00
SkyZeroZx
0f47fda51b test(router): move timeout and autoTick helpers to shared testing utilities
Centralizes common test helpers under testing utilities and updates usages
2026-02-10 07:45:00 -08:00
Angular Robot
11767cabe4 build: update Jasmine to 6.0.0
Jasmine enables `forbidDuplicateNames: true` by default. So we also need to desambiguate duplicate spec names.
2026-02-09 12:15:57 -08:00
Jessica Janiuk
5a0f272519 Revert "feat(router): adds browserUrl input support to router links"
This reverts commit 9505541d32.
2026-02-02 16:32:09 -08:00
SkyZeroZx
9505541d32 feat(router): adds browserUrl input support to router links
Enables specifying a custom browser URL for router links via a new input,
allowing navigation to use an explicit browser URL in navigation options.

Closes #66805
2026-02-02 11:08:18 -08:00
Andrew Scott
b51bab583d feat(router): Add partial ActivatedRouteSnapshot information to canMatch params
This commit adds partial `ActivatedRouteSnapshot` information as the
third parameter of the `canMatch` guard.

resolves #49309
2026-01-26 23:36:06 +00:00
Andrew Scott
da364d2635 refactor(router): Add support for precommitHandler in Navigation integration
The `precommitHandler` of the Navigation API unlocks some of the truly
powerful features for Routers like Angular's which defer the URL
updates. Without the `precommitHandler`, we cannot initiate a navigation
until we are ready to commit the URL because it causes the URL to update
immediately.

With `precommitHandler` support, we are able to create a `NavigateEvent`
_immediately_ on navigation, which allows the browser to show that a
navigation is happening with a loading indicator. Site visitors will
also have the ability to cancel the navigation with the "stop" button.
When we are ready to commit the URL, the precommitHandler supports a
"redirect" function that we can use to first redirect the navigation to
a new location immediately before committing it.

The commit operation is not synchronous because the API waits for all
precommitHandlers to resolve. This commit adds a small bit of handling
to account for this so that the Router's transition does not advance
to the next stage until the URL has been committed.
2026-01-09 10:31:26 -08:00
Andrew Scott
7003e8d241 feat(router): Publish Router's integration with platform Navigation API as experimental
This publishes the work that was done to integrate with the Navigation
API as an experimental router feature. Browser support is limited and in
active development. There are also known bugs in the browser implementations
and only Chromium browsers supported deferred URL updates with the
`precommitHandler`. Relates to #53321, which I would likely not mark as
completed until this is at least in dev preview, which likely won't
happen until it is widely available and potentially delayed until
`precommitHandler` is widely available as well.

The final form of this api might not even be a "router feature" in the end, but instead be
something similar to what other frameworks have to provide different
platform integrations (e.g. `provideNavigationRouter`). That would
support omitting the history-based integration from the bundle when only
the navigation integration is used. Alternatively, the current
`provideRouter` could require one of `withHistory` or `withPlatformNavigation`.
2026-01-07 16:16:06 -08:00
Andrew Scott
97fd1de0ac Revert "refactor(router): Add support for precommitHandler in Navigation integration"
This reverts commit 522fa716b8.
2026-01-07 11:45:58 -05:00
Andrew Scott
522fa716b8 refactor(router): Add support for precommitHandler in Navigation integration
The `precommitHandler` of the Navigation API unlocks some of the truly
powerful features for Routers like Angular's which defer the URL
updates. Without the `precommitHandler`, we cannot initiate a navigation
until we are ready to commit the URL because it causes the URL to update
immediately.

With `precommitHandler` support, we are able to create a `NavigateEvent`
_immediately_ on navigation, which allows the browser to show that a
navigation is happening with a loading indicator. Site visitors will
also have the ability to cancel the navigation with the "stop" button.
When we are ready to commit the URL, the precommitHandler supports a
"redirect" function that we can use to first redirect the navigation to
a new location immediately before committing it.

The commit operation is not synchronous because the API waits for all
precommitHandlers to resolve. This commit adds a small bit of handling
to account for this so that the Router's transition does not advance
to the next stage until the URL has been committed.
2026-01-06 16:10:56 -05:00
Matthieu Riegler
6270bba056 ci: reformat files
This is after we've slightly changed a rule in #66056
2025-12-16 14:44:19 -08:00
Andrew Scott
cc03254b12 refactor(router): Avoid aborting traversal navigations
Unnecessarily aborting traversal navigations will break focus and scroll
restoration. We need to keep them open rather than replacing them with
an identical router-initiated navigation.
2025-12-02 16:45:17 +01:00
Andrew Scott
c25d749d85 feat(router): Execute RunGuardsAndResolvers function in injection context
Allows more sophisticated checks based on information available in DI
(e.g. the router state). Use-cases have been described in #53944 / https://github.com/angular/angular/issues/31843#issuecomment-1890955590

resolves #53944
2025-11-20 17:05:10 -05:00
Andrew Scott
189807ef04 refactor(router): Build out integration with browser Navigation API (#64905)
This further builds out the Router integration with the platform
Navigation API. Key features in this state include:

* History restoration via direct platform APIs rather than markers left on
  `history.state`. This means more guaranteed correctness and less
  internal code to compute traversal restorations.
* Ability to observe navigations triggered outside the Router APIs.
  Practically speaking, this means some navigations can be performed
  through the platform rather than requiring `Router.navigate`. Note
  that because the `NavigateEvent` is never intercepted at this point of
  the implementation, regular anchor tags cannot be used because they
  will still trigger a popstate navigation.

This implementation does _not_ intercept the `NavigateEvent` but future
iterations should. By omitting the interception, we are missing out on
features such as:

* Platform-supported scroll and focus reset
* Holding the navigate event open for the duration of the router
  navigation, allowing for a visual loading indicator in the browser
* Support for intercepting navigations from regular anchor tags (e.g.
  not `RouterLink`s) and converting those to SPA navigations.

PR Close #64905
2025-11-06 17:42:04 +00:00
Andrew Scott
dd09da8ba2
refactor(router): Add provider for integrating with Navigation API and Location shim
This adds a (private) provider for integrating with the browser Navigation API.
This provider ensures that interactions with the `Location` service
use the underlying platform navigation rather than the history and
location APIs.
2025-10-27 09:21:56 +01:00
Andrew Scott
e2346dbfac refactor(router): Compress middle of navigation pipeline to fewer operators (#64480)
This cleans up the navigation transitions a bit by removing some
unnecessary operators. Combining operators makes debugging easier by
making it possible to step through the code.

PR Close #64480
2025-10-24 09:31:05 +02:00
Andrew Scott
4c36659ba9 refactor(router): Add handling for empty observables in guards (#63546)
This fixes a bug introduced in #63485 where `firstValueFrom` was used. This
doesn't work in all situations here because some observables don't
emit before completing. These errors should result in the route matching
logic moving on to the next route.

Note: This is marked as a refactor rather than fix because the commit above is not in
any release yet.

PR Close #63546
2025-09-02 11:50:49 -07:00
Matthieu Riegler
4e0fc81491 feat(router): convert lastSuccessfulNavigation to signal (#63057)
This commit also include an `ng update` migration to ensure `lastSuccessfulNavigation` is invoked.

BREAKING CHANGE: `lastSuccessfulNavigation` is now a signal and needs to be invoked

PR Close #63057
2025-08-13 11:29:01 -07:00
Matthieu Riegler
687c374826 feat(router): add a currentNavigation signal to the Router service. (#63011)
This new signal property is convenient to derive a `isNavigating` state.

`isNavigating = computed(() => !!this.router.currentNavigation())`

DEPRECATED: The Router.getCurrentNavigation method is deprecated. Use the Router.currentNavigation signal instead.

fixes #62958

PR Close #63011
2025-08-06 09:54:53 -07:00
Kristiyan Kostadinov
ddf779e18f Revert "feat(router): add a currentNavigation signal to the Router service. (#62971)" (#63010)
This reverts commit d00b3fed58.

PR Close #63010
2025-08-05 18:02:56 +02:00
Matthieu Riegler
d00b3fed58 feat(router): add a currentNavigation signal to the Router service. (#62971)
This new signal property is convenient to derive a `isNavigating` state.

`isNavigating = computed(() => !!this.router.currentNavigation())`

DEPRECATED: The Router.getCurrentNavigation method is deprecated. Use the Router.currentNavigation signal instead.

fixes #62958

PR Close #62971
2025-08-05 10:05:49 +02:00
Andrew Scott
92b080202d test(router): Use autoTick feature in router tests (#62776)
This updates async router tests to use the jasmine autoTick feature. Observed test timings
for the chromium tests went down from ~7.5s to ~3.5-4s. For node, these decreased from ~5.5s to ~3s.

In addition to the speed improvement, this feature:

* Removes the need to be careful about timeout ordering when there are several timeouts in tests.
* Removes the need to ensure test timeouts are kept sufficiently small
* Reduces overall flakiness

PR Close #62776
2025-07-24 10:04:05 +00:00
Dmitrij Kuba
9c45c322d1 fix(router): ensure preloaded components are properly activated (#62502)
Preloaded components were not being activated in certain scenarios when preloading was enabled. This change ensures that components are correctly activated after being preloaded.

PR Close #62502
2025-07-09 14:39:39 -07:00
Andrew Scott
c5fcb9d7f4 test(router): Add test for empty path redirect and no match (#62176)
this was discovered during some other work in the router that unintentionally changed this behavior

PR Close #62176
2025-06-23 14:18:12 +02:00
Andrew Scott
9cc7c5f38e test(router): Update timeouts to reduce firefox flakiness (#62141)
This updates the timeouts in a couple flakey router tests. Ideally we can use the jasmine
auto ticking as soon as tests are migrated to web test runner and we are on the latest
version of jasmine

PR Close #62141
2025-06-20 14:39:35 -07:00
Joey Perrott
3acc2a5f07 build: migrate router to use rules_js (#61542)
Use ts_project and ng_project for building router

PR Close #61542
2025-05-21 09:53:34 +00:00
Paul Gschwendtner
3a106a35bc build: move private testing helpers outside platform-browser/testing (#61472)
These helpers are often imported by various tests throughout the
repository, but the helpers aren't exported/exposed from the public
entry-point; even though they confusingly reside in there.

This commit fixes this, and moves the helpers into
`packages/private/testing`. This is a preparation for the `ts_project`
migration where we don't want to leverage deep imports between packages.

PR Close #61472
2025-05-20 10:00:43 +00:00
Andrew Scott
0c925af2dd test(router): This commit removes ZoneJS from the router tests (#61078)
There is nothing in the Router that requires ZoneJS and we do not need
`fakeAsync` as a mock clock. We can instead use any mock clock implementation
to speed up test execution.

This removes ZoneJS completely from the bundle of the Router tests.
ZoneJS causes the stacks to be unreadable when combined with the massive
rxjs stack in the router transition.

PR Close #61078
2025-05-05 08:55:01 -07:00
Andrew Scott
e8147df0e1 refactor(router): Move router integration suite to zoneless (#61046)
This commit moves the router integration tests to use zoneless

PR Close #61046
2025-04-29 21:56:01 -07:00
Andrew Scott
f36f2f2cb4 refactor(router): Remove inject helper from router tests (#61046)
This removes the `inject` helper from core/testing in the router tests.

PR Close #61046
2025-04-29 21:56:01 -07:00
Andrew Scott
0bb4bd661e feat(router): Add ability to directly abort a navigation (#60380)
This commit adds the ability to directly abort a navigation through the
`Router.getCurrentNavigation()?.abort()` method. While there are no
feature requests for this, it is a feature that will be necessary for
integration with the navigation API. The API enables better tracking of
an ongoing navigation for SPAs and a site visitor can cancel a
navigation by clicking the stop button in the browser. While this could
technically be done on the transition with an internal jsdoc comment to
hide it from application developers, there's no need.

With this feature, I believe it would be possible to create somewhat of a shim
to integrate with the navigation API even before the router has full support
using the router events to control a deferred navigation that never
commits the URL and always aborts itself on navigation end.

PR Close #60380
2025-04-02 17:30:27 +00:00
Andrew Kushnir
6d3f5752f2 refactor(router): switching to relative imports within the router package (#60557)
This commit updates scripts within `packages/router` to relative imports as a prep work to the upcoming infra updates.

PR Close #60557
2025-04-01 14:54:05 +00:00
Andrew Scott
0142ae1c8e refactor(router): Update tests to not use deprecated string tokens (#60378)
This replaces string tokens in the router tests with functional guads.

PR Close #60378
2025-03-28 11:50:11 +00:00
Andrew Scott
0b6084e1bf refactor(router): split remainder of describes in integration test file (#60313)
to more easily navigate and identify different suites of integration tests,
this commit splits them into several different files

PR Close #60313
2025-03-11 17:13:27 -07:00
Andrew Scott
647550918f refactor(router): split integration test file (#60311)
to more easily navigate and identify different suites of integration tests,
this commit splits them into several different files

PR Close #60311
2025-03-10 16:03:54 -07:00