Commit graph

510 commits

Author SHA1 Message Date
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
Joey Perrott
cbc258eec8 build: remove ts_project_interop infrastructure (#62908)
Remove the interop macros and final usages

PR Close #62908
2025-07-31 09:12:58 +00: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
Joey Perrott
b84859073b build: migrate to use web test runner rules (#62292)
Migrate karma tests throughout the repo to use the new web test runner based rule instead

PR Close #62292
2025-06-26 17:19:10 +00: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
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
3a0cfd544d build: migrate to using new jasmine_test (#62086)
Use the new jasmine_test based on rules_js instead of jasmine_node_test from rules_nodejs

PR Close #62086
2025-06-18 08:27:26 +02:00
Matthieu Riegler
dba912dd07 refactor(platform-browser): replace platform-browser-dynamic with platform-browser (#61498)
The former isn't needed anymore and is now deprecated.

PR Close #61498
2025-05-21 14:01:49 +00: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
Paul Gschwendtner
032b802f54 build: remove irrelevant madge circular deps tests (#61156)
We don't need this tooling anymore because we are already validating
that there are no circular dependencies via the `ng-dev` tooling that
checks `.ts` files directly.

Also these tests never actually failed to my knowledge.

PR Close #61156
2025-05-07 11:28:59 -07:00
Andrew Scott
55a0621cbd test(router): Reduce timeout times (#61155)
Router tests use real async so unnecessarily long timeouts are an issue

PR Close #61155
2025-05-07 11:16:26 -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
Andrew Scott
2e80744581 test(router): Fix slow-running infinite loop test and remove unnecessary duplicate tests (#61076)
The inifinite loop test is a real infinite loop and runs until a stack
overflow happens. In addition, all the promise and observable tests are
just duplicates of the other redirects and don't test any additional
logic. Instead, this change updates one test to return an observable and
another to return a promise

PR Close #61076
2025-04-30 14:18:09 -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 Kushnir
c2987d8402 refactor(core): stop producing ng-reflect attributes by default (#60973)
BREAKING CHANGE:

This commit deprecates `ng-reflect-*` attributes and updates the runtime to stop producing them by default. Please refactor application and test code to avoid relying on `ng-reflect-*` attributes.

To enable a more seamless upgrade to v20, we've added the `provideNgReflectAttributes()` function (can be imported from the `@angular/core` package), which enables the mode in which Angular would be producing those attribites (in dev mode only). You can add the `provideNgReflectAttributes()` function to the list of providers within the bootstrap call.

PR Close #60973
2025-04-24 10:07:35 -07: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
Andrew Scott
953c4b2580 feat(core): Move zoneless change detection to dev preview (#60748)
This commit moves zoneless from experimental to developer preview.

* Update tag on provider API
* Remove "experimental" from provider name
* Move documentation from "experimental features" to "Best practives ->
  Performance" (at least temporarily until there is a better place)

BREAKING CHANGE: `provideExperimentalZonelessChangeDetection` is
renamed to `provideZonelessChangeDetection` as it is now "Developer
Preview" rather than "Experimental".

PR Close #60748
2025-04-23 11:47:56 +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
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
Lukas Spirig
ff98ccb193 feat(router): support custom elements for RouterLink (#60290)
PR Close #60290
2025-03-28 12:16:09 +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
Kristiyan Kostadinov
5e209cb560 feat(core): remove TestBed.get (#60414)
`TestBed.get` isn't type safe and has been deprecated for several years now. These changes remove it from the public API and a follow-up change will add an automated migration to `TestBed.inject`.

BREAKING CHANGE:
* `TestBed.get` has been removed. Use `TestBed.inject` instead.

PR Close #60414
2025-03-19 15:52:26 +01: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
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
Sheik Althaf
fe40143813 refactor(router): remove standalone true (#58950)
removed the standalone true from router package.

PR Close #58950
2024-12-05 16:02:37 -08:00
Sumit Arora
0ea9b8892b test(router): adding test for getLoadedRoutes (#58199)
Added test for getLoadedRoutes with and without loadChildren

PR Close #58199
2024-10-22 09:40:45 -07:00
Matthieu Riegler
09df589e31 refactor(core): Migrate all packages with the explicit-standalone-flag schematic. (#58160)
All components, directives and pipes will now use standalone as default.
Non-standalone decorators have now `standalone: false`.

PR Close #58160
2024-10-14 14:58:57 +00:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Matthieu Riegler
b23113dc96 refactor(common): replace non output EventEmitter with Subject. (#54666)
Semantcly we're shifting away from using `EventEmitter` on non-outputs.

PR Close #54666
2024-09-24 11:58:24 +02:00
Andrew Scott
8f6308457f fix(router): Do not unnecessarily run matcher twice on route matching (#57530)
This commit makes a small update to the route matching algorithm to
avoid running the matcher function of a route twice.

fixes #57511

PR Close #57530
2024-08-27 13:20:58 -07:00
Andrew Scott
b2790813a6 fix(router): Align RouterModule.forRoot errorHandler with provider error handler (#57050)
This change aligns the behavior of the error handler in the
`ExtraOptions` of `RouterModule.forRoot` with the error handler in
`withNavigationErrorHandler`. The changes are:

* Slightly different timing: The handler is called before the
  `NavigationError` emits
* Runs in the injection context, meaning it is more configurable at the
  config location rather than needing to assign the value to the
  `Router.errorHandler` later to get access to injectables
* Can now return `RedirectCommand` to recover from the error and
  redirect without emitting `NavigationError`
* No longer allows arbitrarily overriding return value of the navigation
  promise

BREAKING CHANGE: The `Router.errorHandler` property has been removed.
Adding an error handler should be configured in either
`withNavigationErrorHandler` with `provideRouter` or the `errorHandler`
property in the extra options of `RouterModule.forRoot`. In addition,
the error handler cannot be used to change the return value of the
router navigation promise or prevent it from rejecting. Instead, if you
want to prevent the promise from rejecting, use `resolveNavigationPromiseOnError`.

PR Close #57050
2024-08-12 09:28:08 -07:00
Andrew Scott
f271021e19 feat(router): Add routerOutletData input to RouterOutlet directive (#57051)
This commit adds an input to `RouterOutlet` that allows developers to
pass data from a parent component to the outlet components.
Setting the `routerOutletData` input on `RouterOutlet` makes the value
available to the child component injectors via the `ROUTER_OUTLET_DATA`
token. This token uses a `Signal` type to allow updating the input value
and propogating it to the token rather than needing to make the value
static.

resolves #46283

PR Close #57051
2024-08-09 08:08:26 -07:00
Andrew Scott
6c76c91e15 feat(router): Add defaultQueryParamsHandling to router configuration (#57198)
This commit adds an option to specify the default value for
`queryParamsHandling` in `Router.createUrlTree` when another option is
not specified (or is `null|undefined`).

resolves #12664

PR Close #57198
2024-08-02 15:11:38 +00:00
Andrew Scott
3459289ef0 feat(core): bootstrapModule can configure NgZone in providers (#57060)
This commit allows configuring `NgZone` through the providers for
`bootstrapModule`. Prior to this change, developers had to configure
`NgZone` in the `BootstrapOptions`.

PR Close #57060
2024-07-30 18:03:35 +00:00
Andrew Scott
4343cd2ceb fix(router): routes should not get stale providers (#56798)
This fixes a bug with RouterOutlet and its context where it would reuse
providers from a previously activated route.

fixes #56774

PR Close #56798
2024-07-02 17:10:51 +00:00
Andrew Scott
1d3a7529b4 feat(router): Set a different browser URL from the one for route matching (#53318)
This feature adds a property to the `NavigationBehaviorOptions` that
allows developers to define a different path for the browser's address
bar than the one used to match routes. This is useful for redirects
where you want to keep the browser bar the same as the original
attempted navigation but redirect to a different page, such as a 404 or
error page.

fixes #17004

PR Close #53318
2024-06-13 13:59:45 -07:00
Andrew Scott
a13f5da773 feat(router): Allow UrlTree as an input to routerLink (#56265)
This commit adds `UrlTree` as a valid input to `routerLink`. It
disallows using this together with any inputs that come from
`UrlCreationOptions`, such as `queryParams` or `fragment`.

We could, in the future, decide on a different approach for these, like merging or
replacing those in `urlTree` input. We cannot, however, go the other way
(decide to prevent those inputs if we've already decided to allow it and
using a merging/replacing strategy). For this reason, an error seems the
most reasonable approach to start and we can re-evaluate if there's a
compelling reason to.

fixes #34468

PR Close #56265
2024-06-07 09:33:14 -07:00
Andrew Scott
66ffeca2de fix(router): Scroller should scroll as soon as change detection completes (#55105)
Using `setTimeout` to delay scrolling can result in scrolling in the
next frame and cause noticeable flicker. This commit scrolls as soon as
the next render happens (or in `setTimeout` if a render does not happen
before then).

fixes #53985

PR Close #55105
2024-04-30 09:19:06 -07:00
Andrew Scott
4a42961393 feat(router): withNavigationErrorHandler can convert errors to redirects (#55370)
This commit adds the ability to return `RedirectCommand` from the error
handler provided by `withNavigationErrorHandler`. This will prevent the
error from being surfaced in the `events` observable of the Router and
instead convert the error to a redirect. This allows developers to
have more control over how the Router handles navigation errors. There
are some cases when the application _does not_ want the URL to be reset
when an error occurs.

resolves #42915

PR Close #55370
2024-04-17 15:53:02 -07:00
Andrew Scott
940a3587b7 refactor(router): prevent navigationErrorHandler from breaking transition subscription (#55152)
Following up on #55068, this change prevents errors in the handler from
breaking navigations.

PR Close #55152
2024-04-01 09:47:54 -07:00
Andrew Scott
3839cfbb18 fix(router): Routed components never inherit RouterOutlet EnvironmentInjector (#54265)
This commit ensures components in the route config predictably always
get their providers from the hierarchy available to routes rather than
sometimes being dependent on where they are inserted.

fixes #53369

BREAKING CHANGE: Providers available to the routed components always
come from the injector heirarchy of the routes and never inherit from
the `RouterOutlet`. This means that providers available only to the
component that defines the `RouterOutlet` will no longer be available to
route components in any circumstances. This was already the case
whenever routes defined providers, either through lazy loading an
`NgModule` or through explicit `providers` on the route config.

PR Close #54265
2024-04-01 09:19:13 -07:00
Andrew Scott
87f3f27f90 feat(router): Allow resolvers to return RedirectCommand (#54556)
Returning a `RedirectCommand` from a resolver can be interpreted as
distinctly different from regular resolved data. When a resolver returns
`RedirectCommand` we can interperet this as an intention to redirect in
the same way as other guards.

resolves #29089

PR Close #54556
2024-03-30 10:52:44 -07:00
Andrew Scott
17369ed1e9 refactor(router): Correct resolve value for error handler case (#55068)
This commit fixes the types on the error handler resolve and reject
functions and also ensures that the resolve value matches the API type
(`boolean`, not "any random value returned from `errorHandler`"). This
could be considered a breaking change but I would argue instead that
relying on the return value of the error handler is API misuse because
the promise returned by the router navigation _does not_ include `any`
in its type.

PR Close #55068
2024-03-29 09:16:46 -07:00