Commit graph

1155 commits

Author SHA1 Message Date
Alan Agius
4ed8781301
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.
2025-11-11 12:50:16 -08:00
Shuaib Hasan Akib
b0b834d7f1 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.
2025-11-10 12:04:31 -08:00
arturovt
d3f67f6ca8 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.
2025-11-10 12:04:04 -08:00
arturovt
7724a9460d 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.
2025-11-10 09:48:32 -08:00
Andrew Scott
2db8f2ee75 refactor(router): Add handling of abort event on signal of NavigateEvent
This adds handling of the abort event on the signal of the
`NavigateEvent`, allowing us to cancel the Router's ongoing navigation
transition when its related navigation was aborted.
2025-11-10 08:02:43 -08:00
Andrew Scott
1651908004
refactor(router): Add handler to NavigationInterceptOptions
This adds a handler to the `NavigationInterceptOptions` when we are
intercepting a `NavigateEvent`. This means that the scroll and focus
restoration will be delayed until the handler promise resolves. It also
means that we can provide better indication of an ongoing navigation
event.
2025-11-07 13:32:49 -08:00
Andrew Scott
85d9abb019
refactor(router): Intercept navigate events (unless it's a rollback)
This adds further integration with the browser Navigation API by intercepting the navigation events.
2025-11-06 15:00:08 -08:00
Alan Agius
26fed34e0e
build: format md files
This commit configures prettier to format markdown files.
2025-11-06 10:03:05 -08:00
SkyZeroZx
08a84e03e6 refactor(router): simplify imports and improve option access in RouterScroller tests
Simplifies imports and unifies option access in RouterScroller specs for cleaner and more consistent code
2025-11-06 09:42:41 -08: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
310cc9b71b build: Add dom-navigation types to router (#64905)
As the integration with the browser navigation API is built out, we will want to have the types available

PR Close #64905
2025-11-06 17:42:04 +00:00
SkyZeroZx
ca3ef38143 refactor(common): Removes unused imports to clean up dependencies
Eliminates unnecessary imports to reduce clutter and improve maintainability
2025-11-06 08:35:28 -08:00
Andrew Scott
7f16902a72 refactor(router): Update pre/post wildcard matching to retain 0 or more segment match meaning
Prior to the change to support defining required segments before and after the wildcard, the meaning of the wildcard
path was '0 or more' so path: foo with a child of ** will still match the ** route when the URL is only 'foo'.
If developers want to _require_ something, they can still use path: foo/:anyRequired/**/bar
2025-11-04 17:56:54 +00:00
SkyZeroZx
67da4eb04c refactor(router): remove redundant providedIn: 'root' from injection tokens
Removes unnecessary `providedIn: 'root'` declarations from injection tokens
2025-11-04 00:31:52 +00:00
Kristiyan Kostadinov
b9e2ccdda8 refactor(common): remove unused import (#64699)
Cleans up unused code to improve readability and maintainability.

PR Close #64699
2025-10-30 19:27:33 +00:00
Andrew Scott
c84d372778 feat(router): Support wildcard params with segments trailing (#64737)
this adds support for both leading and trailing segments before/after wildcard
route. Exposig the segments in a new _splat param would require a
breaking change to the return value of the matchers.

fixes https://github.com/angular/angular/issues/60821

PR Close #64737
2025-10-30 15:44:16 +00:00
Andrew Scott
fb569ef614 refactor(core): Move patch toggles inside functions to allow tree shaking
In general, global level const will cause DCE bailouts.
2025-10-29 20:57:47 +00:00
Andrew Scott
5a93eeb6c0 Revert "feat(router): Support wildcard params with segments trailing"
This reverts commit 0a0cc27aea.
Causes internal failures with route matching. Should investigate and add
tests to prevent future regressions.
2025-10-28 18:35:27 +01:00
Shuaib Hasan Akib
8291760f9b 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.
2025-10-28 10:24:22 +01:00
Andrew Scott
0a0cc27aea feat(router): Support wildcard params with segments trailing
this adds support for both leading and trailing segments before/after wildcard
route. Exposig the segments in a new _splat param would require a
breaking change to the return value of the matchers.

fixes https://github.com/angular/angular/issues/60821
2025-10-28 10:23:58 +01:00
Andrew Scott
a03c82564d feat(router): Add scroll behavior controls on router navigation
This commit adds the ability to control the behavior of scrolling in the
`NavigationBehaviorOptions`. The options directly correlate with the
intercept options of the Navigation API `NavigateEvent#intercept`:
https://developer.mozilla.org/en-US/docs/Web/API/NavigateEvent/intercept#scroll

While we do not currently have an integration with the navigation API,
this change would be necessary to provide the ability to configure that behavior
if/when we do. In the meantime, this option is also useful to control
the behavior of scrolling when the in memory scroller is enabled.

resolves #26744
2025-10-27 09:24:26 +01: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
SkyZeroZx
03f90d7e56 docs: Add router config options (#64529)
PR Close #64529
2025-10-23 12:34:55 +02:00
Andrew Scott
d4d6c28023 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:57 +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