@real-router/angular 0.17.51 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { InjectionToken, inject, DestroyRef, ApplicationRef, signal, provideEnvironmentInitializer, makeEnvironmentProviders, makeStateKey, REQUEST, provideAppInitializer, TransferState, assertInInjectionContext, ChangeDetectorRef, effect, untracked, input, TemplateRef, Directive, contentChildren, computed, Component, output, ElementRef } from '@angular/core';
|
|
3
3
|
import { getNavigator, UNKNOWN_ROUTE } from '@real-router/core';
|
|
4
4
|
import { getTransitionSource, createRouteSource, primeErrorSource, createRouteNodeSource, createActiveSource, guardLeaveListener, createRouteEnterGate, createDismissableError } from '@real-router/sources';
|
|
5
|
+
import { putField } from '@real-router/core/utils';
|
|
5
6
|
import { cloneRouter, getPluginApi } from '@real-router/core/api';
|
|
6
7
|
import { hydrateRouter, serializeRouterState } from '@real-router/ssr-utils';
|
|
7
8
|
import { getRouteUtils, startsWithSegment } from '@real-router/route-utils';
|
|
@@ -1407,6 +1408,60 @@ function shouldNavigate(evt) {
|
|
|
1407
1408
|
!evt.ctrlKey &&
|
|
1408
1409
|
!evt.shiftKey);
|
|
1409
1410
|
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Does an anchor's `target` send this navigation somewhere the router cannot
|
|
1413
|
+
* follow? (#1834)
|
|
1414
|
+
*
|
|
1415
|
+
* `target` names the browsing context the author wants the URL loaded into.
|
|
1416
|
+
* Three values are the router's — absent, empty, `_self` — and every other one
|
|
1417
|
+
* goes to the browser, the only thing that can resolve a context name.
|
|
1418
|
+
* Intercepting instead is how a `<Link target="_blank">` ends up reloading the
|
|
1419
|
+
* same tab rather than opening a new one. React Router's
|
|
1420
|
+
* `shouldProcessLinkClick` and TanStack Router's `handleClick` split the same
|
|
1421
|
+
* way; neither reproduces browsing contexts inside the router, and neither does
|
|
1422
|
+
* this.
|
|
1423
|
+
*
|
|
1424
|
+
* ⚠ The split is by SPELLING, not by where the value resolves to, and three
|
|
1425
|
+
* spellings resolve back to this context anyway: `_parent` and `_top` fall back
|
|
1426
|
+
* to `_self` in a document with no ancestor, and `_SELF` matches `_self`
|
|
1427
|
+
* ASCII-case-insensitively (MDN, `<a>` § target). All three are handed to the
|
|
1428
|
+
* browser, which reaches the right destination by a full page load instead of a
|
|
1429
|
+
* transition. Resolving them properly means reproducing frame ancestry and
|
|
1430
|
+
* keyword folding here; both reference routers decline, and the cost is a page
|
|
1431
|
+
* load rather than a wrong destination.
|
|
1432
|
+
*
|
|
1433
|
+
* ⚠ Ask this only about an `<a>`. On a `<button v-link>` or a `<div use:link>`
|
|
1434
|
+
* the attribute is inert markup the browser will not act on, so deferring there
|
|
1435
|
+
* would leave the activation unhandled by anyone. Callers that cannot assume an
|
|
1436
|
+
* anchor ask {@link anchorTargetsAnotherContext} instead, which narrows first;
|
|
1437
|
+
* `target-predicate-authority-1834` owns which call site is in which set.
|
|
1438
|
+
*/
|
|
1439
|
+
function targetsAnotherContext(target) {
|
|
1440
|
+
return Boolean(target) && target !== "_self";
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* The same question, asked about an ELEMENT — for the `use:link` / `v-link`
|
|
1444
|
+
* forms, which attach to whatever element the consumer wrote and so cannot
|
|
1445
|
+
* assume an anchor (#1834). The `<Link>` components pass a value instead
|
|
1446
|
+
* (they render the anchor), and so does Angular's directive (its selector is
|
|
1447
|
+
* `a[realLink]`).
|
|
1448
|
+
*
|
|
1449
|
+
* ⚠ `tagName`, never `instanceof HTMLAnchorElement`, for the reason
|
|
1450
|
+
* `applyLinkA11y` sets out below: the constructor belongs to the realm this
|
|
1451
|
+
* module loaded in, so a real anchor from an iframe `contentDocument` or a
|
|
1452
|
+
* micro-frontend fails the check. Failing it HERE re-intercepts the very
|
|
1453
|
+
* `target="_blank"` click this predicate exists to leave alone.
|
|
1454
|
+
*
|
|
1455
|
+
* Anything that is not an HTML anchor answers `false`: `target` is
|
|
1456
|
+
* anchor-specific markup the browser will not act on, so a `<button use:link>`
|
|
1457
|
+
* or a `<div v-link>` carrying one must still navigate in-app.
|
|
1458
|
+
*/
|
|
1459
|
+
function anchorTargetsAnotherContext(element) {
|
|
1460
|
+
if (element?.tagName !== "A") {
|
|
1461
|
+
return false;
|
|
1462
|
+
}
|
|
1463
|
+
return targetsAnotherContext(element.getAttribute("target"));
|
|
1464
|
+
}
|
|
1410
1465
|
/**
|
|
1411
1466
|
* RFC 3986 fragment encoding: preserve sub-delims (`&`, `=`, `?`, `:`),
|
|
1412
1467
|
* encode space, `%`, control chars, non-ASCII via encodeURI; defensively
|
|
@@ -1485,7 +1540,17 @@ function buildHref(router, routeName, routeParams, routeSearch, hash) {
|
|
|
1485
1540
|
function navigateWithHash(router, routeName, routeParams, routeSearch, hash, extraOptions) {
|
|
1486
1541
|
const opts = { ...extraOptions };
|
|
1487
1542
|
if (hash !== undefined) {
|
|
1488
|
-
opts.hash =
|
|
1543
|
+
// ⚑ `putField`, not `opts.hash = …` (#2141 / #1852). The spread above produces
|
|
1544
|
+
// no own key for this slot unless the caller's extra options carried one, so
|
|
1545
|
+
// a plain assignment walks the prototype: an ambient accessor an application
|
|
1546
|
+
// or a polyfill put on `Object.prototype` takes the value and the navigation
|
|
1547
|
+
// runs without the fragment it was asked for, or — getter-only — throws.
|
|
1548
|
+
//
|
|
1549
|
+
// ⚠ This dir is shared, so one unguarded write here multiplies by its whole
|
|
1550
|
+
// consumer set — `packages/react` is the coverage and authority owner
|
|
1551
|
+
// (#1838) and owns that count. Its scan classifies COMPUTED-key writes only,
|
|
1552
|
+
// which is why a literal slot like this one sat outside it.
|
|
1553
|
+
putField(opts, "hash", hash);
|
|
1489
1554
|
}
|
|
1490
1555
|
const current = router.getState();
|
|
1491
1556
|
// What the navigation gets — the caller's `routeSearch` unless the bypass
|
|
@@ -2734,7 +2799,7 @@ class RealLink {
|
|
|
2734
2799
|
});
|
|
2735
2800
|
}
|
|
2736
2801
|
onClick(event) {
|
|
2737
|
-
if (!shouldNavigate(event) || this.anchor.target
|
|
2802
|
+
if (!shouldNavigate(event) || targetsAnotherContext(this.anchor.target)) {
|
|
2738
2803
|
return;
|
|
2739
2804
|
}
|
|
2740
2805
|
event.preventDefault();
|