MCPcopy Create free account
hub / github.com/angular/angular / RouterLink

Class RouterLink

packages/router/src/directives/router_link.ts:200–597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198 },
199})
200export class RouterLink implements OnChanges, OnDestroy {
201 private hrefAttributeValue = inject(new HostAttributeToken('href'), {optional: true});
202 /** @docs-private */
203 protected readonly reactiveHref = linkedSignal(() => {
204 // Never change href for non-anchor elements
205 if (!this.isAnchorElement) {
206 return this.hrefAttributeValue;
207 }
208 // Track path changes. It's knowing which segments we actually depend on is somewhat difficult
209 this.reactiveRouterState.path();
210 if (this._preserveFragment()) {
211 this.reactiveRouterState.fragment();
212 }
213 const shouldTrackParams = (handling: QueryParamsHandling | undefined | null) =>
214 handling === 'preserve' || handling === 'merge';
215 if (
216 shouldTrackParams(this._queryParamsHandling()) ||
217 shouldTrackParams(this.options?.defaultQueryParamsHandling)
218 ) {
219 this.reactiveRouterState.queryParams();
220 }
221 return this.computeHref(this.createUrlTree());
222 });
223 /**
224 * Represents an `href` attribute value applied to a host element,
225 * when a host element is an `<a>`/`<area>` tag or a compatible custom
226 * element. For other tags, the value is `null`.
227 */
228 get href() {
229 return untracked(this.reactiveHref);
230 }
231 /** @deprecated */
232 set href(value: string | null) {
233 this.reactiveHref.set(value);
234 }
235
236 /**
237 * Represents the `target` attribute on a host element.
238 * This is only used when the host element is
239 * an `<a>`/`<area>` tag or a compatible custom element.
240 */
241 @Input() set target(value: string | undefined) {
242 this._target.set(value);
243 }
244 get target(): string | undefined {
245 return untracked(this._target);
246 }
247
248 /**
249 * @docs-private
250 * @internal
251 */
252 protected _target = signal<string | undefined>(undefined);
253
254 /**
255 * Passed to {@link Router#createUrlTree} as part of the
256 * `UrlCreationOptions`.
257 * @see {@link UrlCreationOptions#queryParams}

Callers

nothing calls this directly

Calls 10

computeHrefMethod · 0.95
createUrlTreeMethod · 0.95
injectFunction · 0.90
linkedSignalFunction · 0.90
InputInterface · 0.90
signalFunction · 0.90
HostListenerInterface · 0.90
fragmentMethod · 0.80
queryParamsMethod · 0.80
pathMethod · 0.45

Tested by

no test coverage detected