Skip to content

Commit a39e3fd

Browse files
SkyZeroZxthePunderWoman
authored andcommitted
docs: update examples to use isActive instead of deprecated Router.isActive (angular#66430)
PR Close angular#66430
1 parent e8c44a0 commit a39e3fd

5 files changed

Lines changed: 38 additions & 7 deletions

File tree

adev/src/content/guide/routing/read-route-state.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,30 @@ The RouterLinkActive directive can also be applied to an ancestor element in ord
323323
```
324324

325325
For more information, check out the [API docs for RouterLinkActive](/api/router/RouterLinkActive).
326+
327+
## Check if a URL is active
328+
329+
The `isActive` function returns a computed signal that tracks whether a given URL is currently active in the router. The signal automatically updates as the router state changes.
330+
331+
```angular-ts
332+
import {Component, inject} from '@angular/core';
333+
import {isActive, Router} from '@angular/router';
334+
335+
@Component({
336+
template: `
337+
<div [class.active]="isSettingsActive()">
338+
<h2>Settings</h2>
339+
</div>
340+
`
341+
})
342+
export class Panel {
343+
private router = inject(Router);
344+
345+
isSettingsActive = isActive('/settings', this.router, {
346+
paths: 'subset',
347+
queryParams: 'ignored',
348+
fragment: 'ignored',
349+
matrixParams: 'ignored'
350+
});
351+
}
352+
```

adev/src/content/guide/routing/route-transition-animations.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Use this callback to customize transition behavior based on navigation context.
122122

123123
```ts
124124
import {inject} from '@angular/core';
125-
import {Router, withViewTransitions} from '@angular/router';
125+
import {Router, withViewTransitions, isActive} from '@angular/router';
126126

127127
withViewTransitions({
128128
onViewTransitionCreated: ({transition}) => {
@@ -137,7 +137,9 @@ withViewTransitions({
137137
queryParams: 'ignored',
138138
};
139139

140-
if (router.isActive(targetUrl, config)) {
140+
const isTargetRouteCurrent = isActive(targetUrl, router, config);
141+
142+
if (isTargetRouteCurrent()) {
141143
transition.skipTransition();
142144
}
143145
},

packages/router/src/directives/router_link_active.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ export class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit
125125
/**
126126
* Options to configure how to determine if the router link is active.
127127
*
128-
* These options are passed to the `Router.isActive()` function.
128+
* These options are passed to the `isActive()` function.
129129
*
130-
* @see {@link Router#isActive}
130+
* @see {@link isActive}
131131
*/
132132
@Input() routerLinkActiveOptions: {exact: boolean} | IsActiveMatchOptions = {exact: false};
133133

packages/router/src/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import {afterNextNavigation} from './utils/navigations';
7070
import {RouterState} from './router_state';
7171

7272
/**
73-
* The equivalent `IsActiveMatchOptions` options for `Router.isActive` is called with `true`
73+
* The equivalent `IsActiveMatchOptions` options for `isActive` is called with `true`
7474
* (exact = true).
7575
*/
7676
export const exactMatchOptions: IsActiveMatchOptions = {
@@ -81,7 +81,7 @@ export const exactMatchOptions: IsActiveMatchOptions = {
8181
};
8282

8383
/**
84-
* The equivalent `IsActiveMatchOptions` options for `Router.isActive` is called with `false`
84+
* The equivalent `IsActiveMatchOptions` options for `isActive` is called with `false`
8585
* (exact = false).
8686
*/
8787
export const subsetMatchOptions: IsActiveMatchOptions = {

packages/router/src/url_tree.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {Router} from './router';
1818
* for the current router state.
1919
*
2020
* @publicApi
21-
* @see {@link Router#isActive}
21+
* @see {@link isActive}
2222
*/
2323
export interface IsActiveMatchOptions {
2424
/**
@@ -84,6 +84,8 @@ const paramCompareMap: Record<ParamMatchOptions, ParamCompareFn> = {
8484
* Returns a computed signal of whether the given url is activated in the Router.
8585
*
8686
* As the router state changes, the signal will update to reflect whether the url is active.
87+
*
88+
* @see [Check if a URL is active](guide/routing/read-route-state#check-if-a-url-is-active)
8789
* @publicApi 21.1
8890
*/
8991
export function isActive(

0 commit comments

Comments
 (0)