Commit graph

1153 commits

Author SHA1 Message Date
Anuj Chhajed
288238abef refactor(core): correct all typeof ngDevMode comparison patterns introduced by #63875
This change replaces all remaining occurrences of `typeof ngDevMode !== undefined`
with the correct `typeof ngDevMode !== 'undefined'` form. This aligns the codebase
with JavaScript typeof semantics and maintains consistency with other Angular code.

(cherry picked from commit 96b79fc393)
2025-12-08 10:30:06 -08:00
arturovt
48b89f9fbe fix(router): handle errors from view transition finished promise
This commit adds a `.catch()` handler to `transition.finished` from `document.startViewTransition` to prevent unhandled promise rejections. The finished promise can reject with `TimeoutError` or `InvalidStateError` when transitions fail during or after the animation phase.

Based on the Blink source code, the `finished` promise can reject with:
* `TimeoutError`: "Transition was aborted because of timeout in DOM update"
* `InvalidStateError`: "Transition was aborted because of invalid state"

This may happen when the DOM update phase exceeds the browser's internal timeout threshold.

(cherry picked from commit b74a0693f2)
2025-12-03 12:17:02 +01:00
Andrew Scott
c2a8934d12 Revert "refactor(router): compress synchronous end to router navigation to single operator"
This reverts commit 71362733cf.
2025-12-02 19:13:07 +01:00
Andrew Scott
71362733cf refactor(router): compress synchronous end to router navigation to single operator
The end of the Router navigation is a block of synchronous logic that
can be compressed into a single operator rather than splitting it across
several, making it harder to step through. The only benefit from the
split is automatic unsubscribe/cancellation, which we can replicate
with an additional 'shouldContinue' check before proceeding.

(cherry picked from commit b7d21e209a)
2025-12-02 16:44:06 +01:00
Tim Deschryver
efe4b72abb docs: fix documentation link for currentNavigation method
(cherry picked from commit 680de24c3c)
2025-12-02 12:02:28 +01:00
SkyZeroZx
a62162d2ee docs: Update router docs to add references and components input fixed syntaxis
(cherry picked from commit 2ac826867b)
2025-11-24 13:18:31 -05:00
Alessio Pelliccione
9d6b86958a docs(docs-infra): fix missing syntax highlighting
closed angular#65565

(cherry picked from commit 7d20f2071c)
2025-11-24 13:13:25 -05:00
Shuaib Hasan Akib
35dc3ecfda refactor(common): update examples to align with Angular best practices
Updated examples to use the standalone component approach and the latest

(cherry picked from commit c7affdfbc9)
2025-11-19 22:29:53 +00:00
SkyZeroZx
9950165145 docs: adds guide references to router APIs
Adds `@see` tags with links to relevant guides in the router documentation.

(cherry picked from commit 718eb7bb3a)
2025-11-13 18:00:24 +00:00
Alan Agius
7811d95b89 refactor(core): improve resource loading with async/await
Refactor  to use async/await for clearer asynchronous operations and enhanced error handling.
Simplify resource caching and streamline the resolution of component templates and styles.
Update  in the router to align with the new async resource resolution.

(cherry picked from commit 4ed8781301)
2025-11-11 12:50:19 -08:00
Shuaib Hasan Akib
e5a19cb736 refactor(router): add ngDevMode guards to InjectionToken names and cleanup imports
Wraps InjectionToken names with `typeof ngDevMode !== 'undefined' && ngDevMode`
checks to enable tree-shaking of descriptive token names in production builds.
This ensures debug-only strings are removed from production bundles, reducing size.

Also removes unused imports found during refactor.

(cherry picked from commit b0b834d7f1)
2025-11-10 12:04:35 -08:00
arturovt
8ab084754b refactor(core): mark VERSION as @__PURE__ for better tree-shaking
Annotate the `new Version(...)` call with `/* @__PURE__ */` to signal to optimizers that the constructor is side-effect free.

Without this hint, bundlers such as Terser or ESBuild may conservatively retain the `VERSION` instantiation even when unused. With the annotation, the constant can be tree-shaken away in production builds if not referenced, reducing bundle size.

(cherry picked from commit d3f67f6ca8)
2025-11-10 12:04:09 -08:00
arturovt
9db114f4ff refactor(router): replace Optional with inject() flags
Replace `@Optional() link: RouterLink` constructor parameter with
`link = inject(RouterLink, {optional: true})` to enable tree-shaking
of the `Optional` decorator and its factory scaffolding.

Bundle size reduction: `Optional` is a runtime value created by
`makeParamDecorator()`. Even in production builds, ESBuild and other
bundlers must keep their factory code because it is referenced via
`Optional`. With `inject()`, this class is no longer referenced,
allowing it and the `makeParamDecorator` scaffolding to be tree-shaken
when unused elsewhere.

Note: This updates the constructor signature but should not be
considered a breaking change. Angular's official guidance is that
directives, components, and pipes should be instantiated by the
framework, not by user code. Directly calling `new RouterLinkActive(...)`
is an unsupported pattern that goes against Angular's design principles.

(cherry picked from commit 7724a9460d)
2025-11-10 09:48:36 -08:00
Alan Agius
3bed9f0f16
build: format md files
This commit configures prettier to format markdown files.
2025-11-06 10:07:13 -08:00
Jessica Janiuk
a3c2fe819a Revert "refactor(common): Removes unused imports to clean up dependencies"
This reverts commit 6d3e0f1a51.
2025-11-06 09:05:05 -08:00
SkyZeroZx
6d3e0f1a51 refactor(common): Removes unused imports to clean up dependencies
Eliminates unnecessary imports to reduce clutter and improve maintainability

(cherry picked from commit ca3ef38143)
2025-11-06 16:35:32 +00:00
SkyZeroZx
f32a364045 refactor(router): remove redundant providedIn: 'root' from injection tokens
Removes unnecessary `providedIn: 'root'` declarations from injection tokens

(cherry picked from commit 67da4eb04c)
2025-11-03 16:31:58 -08:00
Kristiyan Kostadinov
a4fe078969 refactor(common): remove unused import (#64699)
Cleans up unused code to improve readability and maintainability.

PR Close #64699
2025-10-30 19:27:34 +00:00
Andrew Scott
60cc3cbde4 refactor(core): Move patch toggles inside functions to allow tree shaking
In general, global level const will cause DCE bailouts.

(cherry picked from commit fb569ef614)
2025-10-29 13:57:56 -07:00
Shuaib Hasan Akib
ba719f4d15 refactor(router): remove redundant default value from routerOutletData input
Since `input()` defaults to `undefined`, the explicit initializer was unnecessary.
This improves clarity and reduces boilerplate.

(cherry picked from commit 8291760f9b)
2025-10-28 10:24:27 +01:00
Andrew Scott
7a2d029f51 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.

(cherry picked from commit dd09da8ba2)
2025-10-27 09:22:00 +01:00
SkyZeroZx
87afeb833b docs: Add router config options (#64529)
PR Close #64529
2025-10-23 12:34:58 +02:00
Andrew Scott
b7cefeb864 fix(router): handle parenthesized outlets without a name in DefaultUrlSerializer (#64507)
Previously, the `DefaultUrlSerializer` would incorrectly parse URLs with a parenthesized outlet that did not have a name, such as `/(left)`. This would result in an `undefined` outlet name in the serialized URL.

This commit fixes the issue by ensuring that parenthesized outlets without a name are treated as primary outlets.

fixes #58516. Based on the description, either the URL was constructed
manually or by custom serializer.

PR Close #64507
2025-10-23 12:33:59 +02:00
Kristiyan Kostadinov
9d48e534e2 Revert "feat(router): allow router outlet to be set on ng-container (#64562)" (#64584)
This reverts commit 2bd764a3c4.

PR Close #64584
2025-10-22 16:35:38 +00:00
Kristiyan Kostadinov
2bd764a3c4 feat(router): allow router outlet to be set on ng-container (#64562)
Updates the selector for `RouterOutlet` to allow for it to be set on an `ng-container`. This allows it to not render the host node which can affect the layout.

Fixes #64553.

PR Close #64562
2025-10-21 16:49:06 +00:00
Andrew Scott
7afc193016 fix(router): Fix outlet serialization and parsing with no primary children (#64505)
this fixes tree creation, serialization, and parsing of trees created with
children outlets and no primary path

fixes #62384

PR Close #64505
2025-10-20 21:18:46 +00:00
Andrew Scott
f6a73f1913 fix(router): Respect custom UrlSerializer handling of query parameters (#64449)
Previously, query parameters passed to `router.createUrlTree` were simply converted to strings. This meant that any custom serialization logic in a custom `UrlSerializer` was not applied. This could lead to inconsistencies between navigations triggered from the URL bar (which are parsed by the serializer) and navigations triggered programmatically.

This change ensures that query parameters are normalized using the provided `UrlSerializer`. The values are serialized and then parsed to ensure they are in the same format as if they had come from a URL. This allows custom serializers to handle complex objects in query parameters consistently.

Fixes https://github.com/angular/angular/issues/47307

PR Close #64449
2025-10-20 18:42:56 +00:00
Andrew Scott
7fb7511124 fix(router): Surface parse errors in Router.parseUrl (#64503)
logs error in addition to fallback parse

fixes #54937

PR Close #64503
2025-10-20 17:51:29 +00:00
Andrew Scott
25d45ba32d refactor(router): Use promise array for loadComponent (#64450)
This further simplifies the `loadComponent` logic in the Router by using
the promise returned from the config loader directly instead of
converting it to an observable.

PR Close #64450
2025-10-20 17:11:23 +00:00
Jessica Janiuk
c60ab336c9 Revert "fix(router): Respect custom UrlSerializer handling of query parameters (#64449)" (#64511)
This reverts commit 46ae034c70.

PR Close #64511
2025-10-18 00:19:40 +00:00
Jessica Janiuk
e7bdf87ebc Revert "refactor(router): Use promise array for loadComponent (#64450)" (#64510)
This reverts commit cc5d698e0a.

PR Close #64510
2025-10-18 00:19:07 +00:00
Andrew Scott
cc5d698e0a refactor(router): Use promise array for loadComponent (#64450)
This further simplifies the `loadComponent` logic in the Router by using
the promise returned from the config loader directly instead of
converting it to an observable.

PR Close #64450
2025-10-17 17:41:30 +00:00
Andrew Scott
46ae034c70 fix(router): Respect custom UrlSerializer handling of query parameters (#64449)
Previously, query parameters passed to `router.createUrlTree` were simply converted to strings. This meant that any custom serialization logic in a custom `UrlSerializer` was not applied. This could lead to inconsistencies between navigations triggered from the URL bar (which are parsed by the serializer) and navigations triggered programmatically.

This change ensures that query parameters are normalized using the provided `UrlSerializer`. The values are serialized and then parsed to ensure they are in the same format as if they had come from a URL. This allows custom serializers to handle complex objects in query parameters consistently.

Fixes https://github.com/angular/angular/issues/47307

PR Close #64449
2025-10-17 17:30:46 +00:00
SkyZeroZx
13b0706cc5 docs: Add injection context for lazy route loading (#64412)
PR Close #64412
2025-10-15 10:41:53 -07:00
Andrew Scott
2c85d2802f refactor(router): update route config loading to use async/await (#64322)
This simplifies code by using async/await instead of rxjs in the config
loading internals. While loadChildren/loadComponent could _technically_
return a synchronous value, the expectation is that this would be used
for dynamic imports, which are necessarily async.

PR Close #64322
2025-10-13 09:58:10 -07:00
Andrew Scott
e1da41ffdf fix(router): Scroll restoration should use instant scroll behavior for traversals (#64299)
When the scroll position is being restored, this change upates the
behavior to use 'instant' rather than the default 'auto', which will
be whatever the browser behavior is for 'window.scrollTo'. The 'smooth'
behavior does not match how browsers behavior when performing a
traversal navigation for MPAs, which is 'instant'.

related to #58258

PR Close #64299
2025-10-09 11:13:45 -07:00
Jaime Burgos
930460896c docs: add documentation for routerOutletData input and its usage (#64242)
PR Close #64242
2025-10-06 15:20:05 -04:00
SkyZeroZx
fa75e4afb4 docs: Adds guide for customizing page titles with TitleStrategy (#64238)
Improves documentation by explaining how to implement and configure a custom title strategy for centralized control over page titles

PR Close #64238
2025-10-06 15:17:58 -04:00
Andrew Scott
5e61e8d3c3 fix(router): Fix memory leak through Navigation.abort and canDeactivate guards (#64141)
This commit updates the internal transition to handle context retention
through the abort function. This retention chain included the
previousNavigation and setting this to a noop function resolves the
issue.

fixes #63983

PR Close #64141
2025-10-02 17:31:42 +00:00
Kristiyan Kostadinov
f5b50ec20d refactor: clean up explicit standalone flags from tests (#63963)
Since standalone is the default, we can dropn the `standalone: true` flags from our tests.

PR Close #63963
2025-09-22 14:27:34 +00:00
Matthieu Riegler
c50d659509 refactor(core): protect InjectionToken usage of ngDevMode (#63875)
Since those are top level APIs, `ngDevMode` might not be available at runtime if they're invoked before the variable is set.

fixes #62796

PR Close #63875
2025-09-19 21:27:45 +00:00
Kristiyan Kostadinov
8f59295019 refactor(core): remove unnecessary deps arrays (#63823)
We don't need to use the `deps` array syntax anymore since we have the `inject` function. These changes clean up the relevant usages.

PR Close #63823
2025-09-16 16:51:52 +00:00
Matthieu Riegler
5612ad5b45 docs: add alert about routelinkactive being a content query (#63829)
This commit also fixes an issue with alert that we're parse correctly if they were at the end of the markdown string

fixes #52877

PR Close #63829
2025-09-16 15:15:24 +00:00
Andrew Scott
bd54106708 refactor(router): update error checks extending error (#63487)
I forgot about the "setPrototypeOf" fix and had a recency bias for the
NotFoundError in the signal primitives.

PR Close #63487
2025-09-11 16:55:58 +00:00
Matthieu Riegler
5220cea223 build: add a noDuplicateEnumValue rule (#63483)
It caught several legitimate issues.
In the cases I wasn't sure, I just disabled the rule.

fixes #45843

PR Close #63483
2025-09-10 22:16:10 +00:00
AleksanderBodurri
d006721f30 feat(devtools): clean up router tree for stable release (#63081)
Addresses some cleanup items for the router tree:

- No longer loads router ng global APIs as a side effect of importing the router. Rather this is now a runtime step that occurs when provideRouter is called.
- No longer depends on router.navigateByUrl in Angular DevTools. There is now a dedicated global util for this
- Router instance logic no longer depends on token name
- Prevents navigating to lazy or redirect routes (these don't have an associated component)

PR Close #63081
2025-09-02 20:59:15 -07: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
Andrew Scott
bbb46e50d4 refactor(router): Add firstValueFrom helper (#63485)
This fixes a bug introduced in #62994 where `toPromise` was used. This
doesn't work in all situations here because some observables don't
complete. This only affected the redirect path, since the others are
already behind other rxjs code which takes the first value from the user
guards.

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

PR Close #63485
2025-08-29 19:02:04 +00:00
Andrew Scott
6e1599d4cc refactor(router): Add internal flag to control async vs rxjs recognize (#62994)
To aid in hitting external breaking change deadlines without pressure
of fixing everything in g3 first, add an internal opt out flag.

This also adds a privately exported provider to revert to the old
rxjs-based behavior, which can be synchronous, until any issues that
come up are addressed.

PR Close #62994
2025-08-29 08:55:13 -07:00
Andrew Scott
5b53535dd1 fix(router): Update recognize stage to use internally async/await (#62994)
This is effectively a revert of 72e6a948bb.
Debugging the recognize stage is considerably easier with async/await
stacks compared to rxjs. This also improves maintainability and is a
better 1:1 with server-side logic that has been implemented to match
and can be more easily kept in sync.

This also ensures that the recognize step is always async, whereas it
can sometimes be synchronous with rxjs.

BREAKING CHANGE: Router navigations may take several additional
microtasks to complete. Tests have been found to often be highly
dependent on the exact timing of navigation completions with respect to
the microtask queue. The most common fix for tests is to ensure all
navigations have been completed before making assertions. On rare
occasions, this can also affect production applications. This can be
caused by multiple subscriptions to router state throughout the application,
both of which trigger navigations that happened to not conflict with the
previous timing.

PR Close #62994
2025-08-29 08:55:13 -07:00