@tanstack/react-router 0.0.1-beta.261 → 0.0.1-beta.262
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.
- package/build/cjs/link.js +96 -22
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/router.js +0 -112
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +96 -134
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/router.d.ts +1 -2
- package/build/umd/index.development.js +96 -134
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/link.tsx +126 -19
- package/src/router.ts +0 -139
package/build/types/router.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { AnyRouteMatch, RouteMatch } from './Matches';
|
|
|
10
10
|
import { ParsedLocation } from './location';
|
|
11
11
|
import { LocationState } from './location';
|
|
12
12
|
import { SearchSerializer, SearchParser } from './searchParams';
|
|
13
|
-
import {
|
|
13
|
+
import { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, MatchRouteFn, NavigateFn } from './RouterProvider';
|
|
14
14
|
declare global {
|
|
15
15
|
interface Window {
|
|
16
16
|
__TSR_DEHYDRATED__?: HydrationCtx;
|
|
@@ -167,7 +167,6 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
167
167
|
invalidate?: boolean;
|
|
168
168
|
}) => Promise<void>;
|
|
169
169
|
preloadRoute: (navigateOpts?: BuildNextOptions) => Promise<RouteMatch<AnyRoute, any>[]>;
|
|
170
|
-
buildLink: BuildLinkFn<TRouteTree>;
|
|
171
170
|
matchRoute: MatchRouteFn<TRouteTree>;
|
|
172
171
|
injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
|
|
173
172
|
dehydrateData: <T>(key: any, getData: T | (() => T | Promise<T>)) => () => T | undefined;
|
|
@@ -1643,17 +1643,15 @@
|
|
|
1643
1643
|
return _extends.apply(this, arguments);
|
|
1644
1644
|
}
|
|
1645
1645
|
|
|
1646
|
+
const preloadWarning = 'Error preloading route! ☝️';
|
|
1646
1647
|
function useLinkProps(options) {
|
|
1647
|
-
const
|
|
1648
|
-
buildLink
|
|
1649
|
-
} = useRouter();
|
|
1648
|
+
const router = useRouter();
|
|
1650
1649
|
const matchPathname = useMatch({
|
|
1651
1650
|
strict: false,
|
|
1652
1651
|
select: s => s.pathname
|
|
1653
1652
|
});
|
|
1654
1653
|
const {
|
|
1655
1654
|
// custom props
|
|
1656
|
-
type,
|
|
1657
1655
|
children,
|
|
1658
1656
|
target,
|
|
1659
1657
|
activeProps = () => ({
|
|
@@ -1668,8 +1666,8 @@
|
|
|
1668
1666
|
to,
|
|
1669
1667
|
state,
|
|
1670
1668
|
mask,
|
|
1671
|
-
preload,
|
|
1672
|
-
preloadDelay,
|
|
1669
|
+
preload: userPreload,
|
|
1670
|
+
preloadDelay: userPreloadDelay,
|
|
1673
1671
|
replace,
|
|
1674
1672
|
startTransition,
|
|
1675
1673
|
resetScroll,
|
|
@@ -1683,27 +1681,100 @@
|
|
|
1683
1681
|
onTouchStart,
|
|
1684
1682
|
...rest
|
|
1685
1683
|
} = options;
|
|
1686
|
-
|
|
1684
|
+
|
|
1685
|
+
// If this link simply reloads the current route,
|
|
1686
|
+
// make sure it has a new key so it will trigger a data refresh
|
|
1687
|
+
|
|
1688
|
+
// If this `to` is a valid external URL, return
|
|
1689
|
+
// null for LinkUtils
|
|
1690
|
+
|
|
1691
|
+
const dest = {
|
|
1687
1692
|
from: options.to ? matchPathname : undefined,
|
|
1688
1693
|
...options
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
+
};
|
|
1695
|
+
let type = 'internal';
|
|
1696
|
+
try {
|
|
1697
|
+
new URL(`${to}`);
|
|
1698
|
+
type = 'external';
|
|
1699
|
+
} catch {}
|
|
1700
|
+
if (type === 'external') {
|
|
1694
1701
|
return {
|
|
1695
|
-
href
|
|
1702
|
+
href: to
|
|
1696
1703
|
};
|
|
1697
1704
|
}
|
|
1698
|
-
const
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1705
|
+
const next = router.buildLocation(dest);
|
|
1706
|
+
const preload = userPreload ?? router.options.defaultPreload;
|
|
1707
|
+
const preloadDelay = userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0;
|
|
1708
|
+
const isActive = useRouterState({
|
|
1709
|
+
select: s => {
|
|
1710
|
+
// Compare path/hash for matches
|
|
1711
|
+
const currentPathSplit = s.location.pathname.split('/');
|
|
1712
|
+
const nextPathSplit = next.pathname.split('/');
|
|
1713
|
+
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
1714
|
+
// Combine the matches based on user router.options
|
|
1715
|
+
const pathTest = activeOptions?.exact ? s.location.pathname === next.pathname : pathIsFuzzyEqual;
|
|
1716
|
+
const hashTest = activeOptions?.includeHash ? s.location.hash === next.hash : true;
|
|
1717
|
+
const searchTest = activeOptions?.includeSearch ?? true ? deepEqual(s.location.search, next.search, true) : true;
|
|
1718
|
+
|
|
1719
|
+
// The final "active" test
|
|
1720
|
+
return pathTest && hashTest && searchTest;
|
|
1721
|
+
}
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
// The click handler
|
|
1725
|
+
const handleClick = e => {
|
|
1726
|
+
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
1727
|
+
e.preventDefault();
|
|
1728
|
+
|
|
1729
|
+
// All is well? Navigate!
|
|
1730
|
+
router.commitLocation({
|
|
1731
|
+
...next,
|
|
1732
|
+
replace,
|
|
1733
|
+
resetScroll,
|
|
1734
|
+
startTransition
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
|
|
1739
|
+
// The click handler
|
|
1740
|
+
const handleFocus = e => {
|
|
1741
|
+
if (preload) {
|
|
1742
|
+
router.preloadRoute(dest).catch(err => {
|
|
1743
|
+
console.warn(err);
|
|
1744
|
+
console.warn(preloadWarning);
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
const handleTouchStart = e => {
|
|
1749
|
+
if (preload) {
|
|
1750
|
+
router.preloadRoute(dest).catch(err => {
|
|
1751
|
+
console.warn(err);
|
|
1752
|
+
console.warn(preloadWarning);
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1755
|
+
};
|
|
1756
|
+
const handleEnter = e => {
|
|
1757
|
+
const target = e.target || {};
|
|
1758
|
+
if (preload) {
|
|
1759
|
+
if (target.preloadTimeout) {
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
target.preloadTimeout = setTimeout(() => {
|
|
1763
|
+
target.preloadTimeout = null;
|
|
1764
|
+
router.preloadRoute(dest).catch(err => {
|
|
1765
|
+
console.warn(err);
|
|
1766
|
+
console.warn(preloadWarning);
|
|
1767
|
+
});
|
|
1768
|
+
}, preloadDelay);
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
const handleLeave = e => {
|
|
1772
|
+
const target = e.target || {};
|
|
1773
|
+
if (target.preloadTimeout) {
|
|
1774
|
+
clearTimeout(target.preloadTimeout);
|
|
1775
|
+
target.preloadTimeout = null;
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1707
1778
|
const composeHandlers = handlers => e => {
|
|
1708
1779
|
if (e.persist) e.persist();
|
|
1709
1780
|
handlers.filter(Boolean).forEach(handler => {
|
|
@@ -1751,6 +1822,9 @@
|
|
|
1751
1822
|
}) : props.children
|
|
1752
1823
|
}));
|
|
1753
1824
|
});
|
|
1825
|
+
function isCtrlEvent(e) {
|
|
1826
|
+
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
1827
|
+
}
|
|
1754
1828
|
|
|
1755
1829
|
// @ts-nocheck
|
|
1756
1830
|
|
|
@@ -1880,7 +1954,6 @@
|
|
|
1880
1954
|
//
|
|
1881
1955
|
|
|
1882
1956
|
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
1883
|
-
const preloadWarning = 'Error preloading route! ☝️';
|
|
1884
1957
|
class Router {
|
|
1885
1958
|
// Option-independent properties
|
|
1886
1959
|
tempLocationKey = `${Math.round(Math.random() * 10000000)}`;
|
|
@@ -2758,114 +2831,6 @@
|
|
|
2758
2831
|
});
|
|
2759
2832
|
return matches;
|
|
2760
2833
|
};
|
|
2761
|
-
buildLink = dest => {
|
|
2762
|
-
// If this link simply reloads the current route,
|
|
2763
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
2764
|
-
|
|
2765
|
-
// If this `to` is a valid external URL, return
|
|
2766
|
-
// null for LinkUtils
|
|
2767
|
-
|
|
2768
|
-
const {
|
|
2769
|
-
to,
|
|
2770
|
-
preload: userPreload,
|
|
2771
|
-
preloadDelay: userPreloadDelay,
|
|
2772
|
-
activeOptions,
|
|
2773
|
-
disabled,
|
|
2774
|
-
target,
|
|
2775
|
-
replace,
|
|
2776
|
-
resetScroll,
|
|
2777
|
-
startTransition
|
|
2778
|
-
} = dest;
|
|
2779
|
-
try {
|
|
2780
|
-
new URL(`${to}`);
|
|
2781
|
-
return {
|
|
2782
|
-
type: 'external',
|
|
2783
|
-
href: to
|
|
2784
|
-
};
|
|
2785
|
-
} catch (e) {}
|
|
2786
|
-
const nextOpts = dest;
|
|
2787
|
-
const next = this.buildLocation(nextOpts);
|
|
2788
|
-
const preload = userPreload ?? this.options.defaultPreload;
|
|
2789
|
-
const preloadDelay = userPreloadDelay ?? this.options.defaultPreloadDelay ?? 0;
|
|
2790
|
-
|
|
2791
|
-
// Compare path/hash for matches
|
|
2792
|
-
const currentPathSplit = this.latestLocation.pathname.split('/');
|
|
2793
|
-
const nextPathSplit = next.pathname.split('/');
|
|
2794
|
-
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
2795
|
-
// Combine the matches based on user this.options
|
|
2796
|
-
const pathTest = activeOptions?.exact ? this.latestLocation.pathname === next.pathname : pathIsFuzzyEqual;
|
|
2797
|
-
const hashTest = activeOptions?.includeHash ? this.latestLocation.hash === next.hash : true;
|
|
2798
|
-
const searchTest = activeOptions?.includeSearch ?? true ? deepEqual(this.latestLocation.search, next.search, true) : true;
|
|
2799
|
-
|
|
2800
|
-
// The final "active" test
|
|
2801
|
-
const isActive = pathTest && hashTest && searchTest;
|
|
2802
|
-
|
|
2803
|
-
// The click handler
|
|
2804
|
-
const handleClick = e => {
|
|
2805
|
-
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
2806
|
-
e.preventDefault();
|
|
2807
|
-
|
|
2808
|
-
// All is well? Navigate!
|
|
2809
|
-
this.commitLocation({
|
|
2810
|
-
...next,
|
|
2811
|
-
replace,
|
|
2812
|
-
resetScroll,
|
|
2813
|
-
startTransition
|
|
2814
|
-
});
|
|
2815
|
-
}
|
|
2816
|
-
};
|
|
2817
|
-
|
|
2818
|
-
// The click handler
|
|
2819
|
-
const handleFocus = e => {
|
|
2820
|
-
if (preload) {
|
|
2821
|
-
this.preloadRoute(nextOpts).catch(err => {
|
|
2822
|
-
console.warn(err);
|
|
2823
|
-
console.warn(preloadWarning);
|
|
2824
|
-
});
|
|
2825
|
-
}
|
|
2826
|
-
};
|
|
2827
|
-
const handleTouchStart = e => {
|
|
2828
|
-
if (preload) {
|
|
2829
|
-
this.preloadRoute(nextOpts).catch(err => {
|
|
2830
|
-
console.warn(err);
|
|
2831
|
-
console.warn(preloadWarning);
|
|
2832
|
-
});
|
|
2833
|
-
}
|
|
2834
|
-
};
|
|
2835
|
-
const handleEnter = e => {
|
|
2836
|
-
const target = e.target || {};
|
|
2837
|
-
if (preload) {
|
|
2838
|
-
if (target.preloadTimeout) {
|
|
2839
|
-
return;
|
|
2840
|
-
}
|
|
2841
|
-
target.preloadTimeout = setTimeout(() => {
|
|
2842
|
-
target.preloadTimeout = null;
|
|
2843
|
-
this.preloadRoute(nextOpts).catch(err => {
|
|
2844
|
-
console.warn(err);
|
|
2845
|
-
console.warn(preloadWarning);
|
|
2846
|
-
});
|
|
2847
|
-
}, preloadDelay);
|
|
2848
|
-
}
|
|
2849
|
-
};
|
|
2850
|
-
const handleLeave = e => {
|
|
2851
|
-
const target = e.target || {};
|
|
2852
|
-
if (target.preloadTimeout) {
|
|
2853
|
-
clearTimeout(target.preloadTimeout);
|
|
2854
|
-
target.preloadTimeout = null;
|
|
2855
|
-
}
|
|
2856
|
-
};
|
|
2857
|
-
return {
|
|
2858
|
-
type: 'internal',
|
|
2859
|
-
next,
|
|
2860
|
-
handleFocus,
|
|
2861
|
-
handleClick,
|
|
2862
|
-
handleEnter,
|
|
2863
|
-
handleLeave,
|
|
2864
|
-
handleTouchStart,
|
|
2865
|
-
isActive,
|
|
2866
|
-
disabled
|
|
2867
|
-
};
|
|
2868
|
-
};
|
|
2869
2834
|
matchRoute = (location, opts) => {
|
|
2870
2835
|
location = {
|
|
2871
2836
|
...location,
|
|
@@ -2971,9 +2936,6 @@
|
|
|
2971
2936
|
return imported[key || 'default'](...args);
|
|
2972
2937
|
};
|
|
2973
2938
|
}
|
|
2974
|
-
function isCtrlEvent(e) {
|
|
2975
|
-
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2976
|
-
}
|
|
2977
2939
|
class SearchParamError extends Error {}
|
|
2978
2940
|
class PathParamError extends Error {}
|
|
2979
2941
|
function getInitialRouterState(location) {
|