Commit graph

815 commits

Author SHA1 Message Date
Kristiyan Kostadinov
660444fbf2 fix(router): attempt to resolve component resources in JIT mode (#63062)
In #62758 we started loading the component resources during bootstrap in JIT mode to ensure that they're in place by the time we create the component. This won't work for lazy-loaded components in the router, because they don't exist at bootstrap time.

These changes add similar logic when the router loads a component.

PR Close #63062
2025-08-08 14:18:21 -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
SkyZeroZx
52b8e07d6e feat(platform-browser): Warns on conflicting hydration and blocking navigation (#62963)
Adds an internal token to detect when both hydration and blocking initial navigation are enabled. Logs a warning during app initialization if this unsupported combination is found, helping developers avoid misconfiguration and potential runtime issues.

PR Close #62963
2025-08-05 18:16:10 +02: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
Matthieu Riegler
af866249cd docs: fix ActivateRoute example (#62855)
PR Close #62855
2025-07-29 12:17:45 +00:00
arturovt
e9f215624f fix(router): handle errors from view transition readiness (#62535)
This commit adds a `.catch()` handler to `transition.ready` from `document.startViewTransition` to prevent `AbortError`s in Safari when `startViewTransition` is called synchronously multiple times.

PR Close #62535
2025-07-14 11:39:56 -07: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
9833d9ea47 feat(router): Run loadComponent and loadChildren functions in the route's injection context (#62133)
This updates the loader code to run the `loadComponent` and
`loadChildren` functions in the appropriate injection context for the
route.

A primary motiviation for this feature is to bring `loadChildren` with
standalone components and the routes array to
feature-parity with what was possible when using `loadChildren` and a
module that provided routes via the `ROUTES` token and a factory
function (which would have injection context).

fixes #51532

PR Close #62133
2025-06-24 09:39:48 +00:00
Ben Hong
5f6e336b21 docs: add dedicated redirecting routes guide (#62005)
docs: update language block

Co-authored-by: Matthieu Riegler <kyro38@gmail.com>

docs: enhance redirects function docs

docs: fix future tense usage

docs: update phrasing to be present tense

docs: update redirect guides to use better phrasing and examples

docs: fix typo on code example

Co-authored-by: Andrew Scott <atscott01@gmail.com>

docs: fix typo in code example

Co-authored-by: Andrew Scott <atscott01@gmail.com>

docs: update syntax of code snippet

Co-authored-by: Andrew Scott <atscott01@gmail.com>

docs: update description on redirect function and api docs

PR Close #62005
2025-06-18 09:07:32 +02:00
Andrew Scott
0e58e1f642 docs(router): Update view transition types to dev preview (#61787)
This updates the documented state of the view transition interfaces. The withViewTransitions feature was already marked dev preview

PR Close #61787
2025-06-02 12:42:19 -04:00
Charles Lyding
a07413abed refactor(router): add return types to exported functions (#61310)
Return types for exported functions from the router package have now been
added. This provides preparation for the inclusion of additional linting
rules which will eventually enforce the presence of return types for
functions. It also improves readability and type correctness within the
code.

PR Close #61310
2025-05-14 08:57:35 -07:00
Paul Gschwendtner
810b0a7e5c refactor: add explicit types for exports relying on inferred call return type (#61312)
As part of the Bazel toolchain migration we noticed that implicit types
generated by the TypeScript compiler sometimes end up referencing types
from other packages (i.e. cross-package imports).

These imports currently work just because the Bazel `ts_library` and
`ng_module` rules automatically inserted a `<amd-module
name="@angular/x" />` into `.d.ts` of packages. This helped TS figure
out how to import a given file. Notably this is custom logic that is not
occuring in vanilla TS or Angular compilations—so we will drop this
magic as part of the toolchain cleanup!

To improve code quality and keep the existing behavior working, we are
doing the following:

- adding a lint rule that reduces the risk of such imports breaking. The
  failure scenario without the rule is that API goldens show unexpected
  diffs, and types might be duplicated in a different package!

- keeping the `<amd-module` headers, but we manually insert them into
  the package entry-points. This should ensure we don't regress
  anywhere; while we also improved general safety around this above.

Long-term, isolated declarations or a lint rule from eslint-typescript
can make this even more robust.

PR Close #61312
2025-05-13 22:45:18 +00:00
Miles Malerba
c0e9fc103f docs: rename @nodoc to @docs-private (#61194)
This aligns with how angular/components marks their hidden APIs.
`@nodoc` has been broken since the switch to adev, this change should
properly hide the APIs again.

PR Close #61194
2025-05-09 10:23:00 -07:00
Andrew Scott
ce5a94319c refactor(router): Avoid unnecessary href updates on navigations for routerlink (#60875)
The `RouterLink` href does not depend on the state of the router unless
it uses the `fragment` or `queryParams`. This doesn't bother
unsubscribing from the events if the inputs change in a way to no longer
depend on those values since inputs changing is quite rare (and even
more rare for query params handling or preserveFragment to change).

PR Close #60875
2025-05-07 11:31:08 -07:00
Andrew Scott
c53310ee81 refactor(router): Update RouterLink href to use host binding and signals (#60875)
This commit updates the method of setting the href attribute on
`RouterLink` to use built in host binding rather than custom attribute
setting and sanitization. The advantage here would be automatic handling
of the sanitization and avoiding of writing the same value to the DOM
that we had before.

This change does mean that we _always_ write to the href attribute where
before we only wrote to it when the elemnt was known to support `href`.
That said, the implementation attempts to retain behavior that is as
close as possible: the original value of `href` is used and never updated.

PR Close #60875
2025-05-07 11:31:08 -07: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
Klaas Cuvelier
d8532bc87d docs(router): update typing for skipLocationChange in RedirectCommand example (#61119)
The example for the RedirectCommand used a string for skipLocationChange, changed this to a boolean

PR Close #61119
2025-05-05 08:47:52 -07:00
Matthieu Riegler
f580318411 docs(docs-infra): Add version of introduction for APIs (#60814)
For new APIs we'll mention since when a particular API is in its current status (experimental, devPreview, stable)

fixes #49668

PR Close #60814
2025-05-02 07:51:33 -07:00
Andrew Scott
da6fa0f402 refactor(router): Remove outdated comment (#61086)
removes outdated comment in router code

PR Close #61086
2025-05-01 10:09:15 -07:00
Andrew Scott
c0ae032362 refactor(router): Remove unnecessary runOutsideAngular in view transition helper (#61068)
This refactor removes the unnecessary `runOutsideAngular` call in the
view transition helper. The resolved promise re-enters the zone in the
transition, so that will trigger the Angular zone anyways. If it didn't do that,
it risks activated the route outside the zone, which is a bigger risk.
Regardless, this function is only run once per navigation, so even if it
_did_ result in an extra promise/timeout inside the zone, this is not
excessive. Using ZoneJS to trigger rendering is known to overreact to events.
Using `OnPush` or zoneless is more effective at mitigating this issue.

PR Close #61068
2025-04-30 14:18:49 -07:00
Alan Agius
b250bb0a74 refactor(router): produce error message when canMatch is used with redirectTo (#60958)
Redirects in the router are handled before `canMatch` guards are evaluated. As a result, `canMatch` will not run for routes that include a redirect. Instead of silently ignoring this misconfiguration, developers should be alerted to help them understand why it doesn't behave as expected.

Closes: #60957

PR Close #60958
2025-04-29 10:32:02 -07:00
Andrew Kushnir
57794f0256 Revert "refactor(router): produce error message when canMatch is used with redirectTo (#60958)" (#60989)
This reverts commit 907f9bd3b8.

PR Close #60989
2025-04-23 17:48:27 +00:00
arturovt
a93b6e8931 refactor(router): remove Compiler injectee from RouterPreloader (#60945)
This commit removes the `Compiler` injectee from the `RouterPreloader` constructor. It's unused but was still being referenced in the factory definition: `static ɵfac = ɵɵngDeclareFactory(...)`.

PR Close #60945
2025-04-23 15:18:22 +02:00
MeddahAbdellah
62de7d930a feat(router): add asynchronous redirects (#60863)
Adds support for asynchronous redirects in the router, allowing redirect logic to be resolved dynamically (e.g., via API or async function). This enhances routing flexibility and supports more complex navigation scenarios.

BREAKING CHANGE: The `RedirectFn` can now return `Observable` or
`Promise`. Any code that directly calls functions returning this type
may need to be adjusted to account for this.

PR Close #60863
2025-04-23 13:38:49 +02:00
Alan Agius
907f9bd3b8 refactor(router): produce error message when canMatch is used with redirectTo (#60958)
Redirects in the router are handled before `canMatch` guards are evaluated. As a result, `canMatch` will not run for routes that include a redirect. Instead of silently ignoring this misconfiguration, developers should be alerted to help them understand why it doesn't behave as expected.

Closes: #60957

PR Close #60958
2025-04-23 13:38:01 +02:00
Philipp Burgmer
2419060fef fix(router): relax required types on router commands to readonly array (#60345)
Only require a readonly array as input for router commands instead of a writable array. Router itself does not need writable access to the array of commands. If router requires a writable array somebody on the outside would have to spread a readonly array to a new writable array. We can avoid this by just require what route actually needs.

Fixes #60269

BREAKING CHANGE: Several methods in the public API of the Router which
required writable arrays have now been updated to accept readonly
arrays when no mutations are done.

PR Close #60345
2025-04-17 16:21:57 +02:00
Andrew Scott
72dd1330f2 refactor(router): Use NavigationTrigger more consistently and move events helper next to definitions (#60736)
This adjusts code to use `NavigationTrigger` type where appropriate and
moves the `isPublicRouterEvent` next to the private event type union to
make it more obvious that it should be updated along with any updates to
the private type union.

PR Close #60736
2025-04-11 14:53:11 -04:00
arturovt
b1c2a8ac38 refactor(router): replace APP_INITIALIZER (#60719)
The `APP_INITIALIZER` is deprecated. Replaced with `provideAppInitializer`.

PR Close #60719
2025-04-08 16:06:04 -07:00
Andrew Scott
a997a886d9 refactor(router): use performance API for router view transitions (#60790)
Adds feature tracking for view transitions.

PR Close #60790
2025-04-08 14:02:28 -07:00
Matthieu Riegler
ba79f23e2e refactor(router): remove dependency on @types/dom-view-transitions (#60731)
The types have been shipped in TS 5.6

PR Close #60731
2025-04-08 09:01:41 -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 Scott
a5e8294376 refactor(router): Update StateManager base class with common concrete implementations (#60617)
This commit updates the `StateManager` base class to contain common
concrete implementations that would be the same regardless of whether
the state manager is backed by the browser history API or the Navigation
API.

PR Close #60617
2025-04-01 14:05:43 +00:00
Andrew Kushnir
1fed7dc5a7 refactor(router): drop special handling of the OutletInjector (#58351)
This commit updates the OutletInjector and related code to avoid special handling of that injector. The main code that had special handling was refactored to no longer require is in https://github.com/angular/angular/pull/56763, this commit completes the cleanup.

PR Close #58351
2025-03-31 20:46:01 +00:00
Lukas Spirig
ff98ccb193 feat(router): support custom elements for RouterLink (#60290)
PR Close #60290
2025-03-28 12:16:09 +00:00
Andrew Scott
1226eaad51 fix(router): Add missing types to transition (#60307)
The 'types' property was added recently and is available in all browsers that support view transitions

fixes #60285

PR Close #60307
2025-03-28 11:51:06 +00:00
Andrew Scott
c57951d58f fix(router): Remove 'any' type from route guards (#60378)
This commit removes `'any'` from the type union for router guards and
replaces it with 'string', which will eventually also be removed. This
change allows TypeScript to infer the parameter types of functions when
using functional guards and enables stricter type-checking to ensure the
guard array contains valid values.

BREAKING CHANGE: The guards arrays on `Route` no longer include `any` in
the type union. The union includes functions for the functional guards
as well as a type matching `Injector.get`: `ProviderToken<T>|string`.
Note that string is still deprecated on both the route guards and
`Injector.get`.

PR Close #60378
2025-03-28 11:50:11 +00:00
Andrew Scott
997117bb76 refactor(router): Clean up the transition subject (#60357)
This commit cleans up the transition subject a bit so it doesn't use a dummy
initial value. It also avoids copying over data from the previous
request when a new one is created.

PR Close #60357
2025-03-14 11:16:15 +01:00
Andrew Scott
c054d620dd refactor(router): Update to use early return to reduce nesting (#60377)
Updates a switchTap body to use early return to reduce nesting

PR Close #60377
2025-03-14 11:15:28 +01:00
Andrew Scott
7677578695 refactor(router): Add safe navigation operator (#60314)
Adds safe navigation operator to account for tests spying on navigateByUrl

PR Close #60314
2025-03-11 12:59:43 -07:00
Kristiyan Kostadinov
611baaf069 feat(core): remove InjectFlags from public API (#60318)
Removes the deprecated `InjectFlags` symbol from the `@angular/core` public API, as well as all the places that accept it. The previous commit includes an automated migration to switch over to the new way of passing in flags.

BREAKING CHANGE:
* `InjectFlags` has been removed.
* `inject` no longer accepts `InjectFlags`.
* `Injector.get` no longer accepts `InjectFlags`.
* `EnvironmentInjector.get` no longer accepts `InjectFlags`.
* `TestBed.get` no longer accepts `InjectFlags`.
* `TestBed.inject` no longer accepts `InjectFlags`.

PR Close #60318
2025-03-11 11:33:09 -07:00
Vlad Boisa
a129ae5c1f docs: fix one broke link by #57591 (#60237)
Fix 1 link in adev toolchain `{@link forRoot}`
PR Close #60237
2025-03-11 09:24:02 -07:00
Andrew Scott
219f41d049 fix(router): Prevent dangling promise rejections from internal navigations (#60162)
Though the plan is to change the default behavior or the router to
instead resolve the navigation promise with `false` to match all other
failed navigations, we should still prevent dangling promise rejections
from navigations triggered internally when developers opt to use the old
(current) behavior.

PR Close #60162
2025-03-06 07:58:18 -08:00
Samuel Perez
6dd8cce155 docs: fix all brokens links on the API pages (#59162)
This PR fix is for the broken links on the API
pages mentioned in issue #57591.

PR Close #59162
2025-03-04 20:07:23 +00:00
Andrew Scott
db2f2d99c8 fix(router): Scroller should scroll as soon as change detection completes (#60086)
Using `setTimeout` to delay scrolling can result in scrolling in the
next frame and cause noticeable flicker. This commit races rAF and
timeout to ensure scroll happens before the render.

fixes #53985

PR Close #60086
2025-02-25 14:17:07 -05:00
Andrew Scott
7c12cb1df9 feat(router): Allow resolvers to read resolved data from ancestors (#59860)
This commit updates the resolver execution to ensure that resolvers in
children routes are able to read the resolved data from anything above
them in the route tree. Because resolvers on one level block execution
of those below, it seems more of an oversight in the initial
implementation than anything else that this wasn't already possible.

resolves #47287

PR Close #59860
2025-02-25 12:34:40 -05:00
arturovt
c7b6e1107c fix(router): prevent error handling when injector is destroyed (#59457)
In this commit, we prevent error handling when the root injector is already destroyed. This may happen when the observable completes before emitting a value, which would trigger a `catchError` block that attempts to call `runInInjectionContext` on a destroyed injector.

PR Close #59457
2025-01-23 14:21:07 -08:00
Matt Janssen
16b08853bc docs(router): Fix small grammatical errors (#59568)
Improves readability.
PR Close #59568
2025-01-17 13:21:26 -08:00
arturovt
c51c66ef1e refactor(router): drop forRoot guard in production (#59458)
In this commit, we switch from decorators (which also produce redundant metadata, such as in the `declareFactory`
instruction) to the `inject` function to drop the `ROUTER_FORROOT_GUARD` token in production. This token factory function is only in development mode but is still referenced in the constructor due to the `@Inject(ROUTER_FORROOT_GUARD)` decorator.

PR Close #59458
2025-01-16 13:55:49 -08:00
hawkgs
b9155b5121 docs: set syntax highlighting to the remaining Markdown code examples blocks (#59088)
There are some code blocks that slipped through the initial Regex-es.

Related to #59026

PR Close #59088
2025-01-14 15:14:02 -05:00