@tanstack/react-router 1.0.1 → 1.0.3

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.
@@ -85,7 +85,7 @@ export type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {
85
85
  'Valid Route IDs': RouteIds<TRouteTree>;
86
86
  };
87
87
  export type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string ? TTo extends string ? TTo extends '.' ? TFrom : TTo extends `./` ? Join<[TFrom, '/']> : TTo extends `./${infer TRest}` ? ResolveRelativePath<TFrom, TRest> : TTo extends `/${infer TRest}` ? TTo : Split<TTo> extends ['..', ...infer ToRest] ? Split<TFrom> extends [...infer FromRest, infer FromTail] ? ToRest extends ['/'] ? Join<[...FromRest, '/']> : ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ToRest extends ['/'] ? Join<[TFrom, '/']> : ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
88
- export declare function useLinkProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(options: UseLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): React.AnchorHTMLAttributes<HTMLAnchorElement>;
88
+ export declare function useLinkProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>({ from, ...options }: UseLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): React.AnchorHTMLAttributes<HTMLAnchorElement>;
89
89
  export interface LinkComponent<TProps extends Record<string, any> = {}> {
90
90
  <TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: LinkProps<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & TProps & React.RefAttributes<HTMLAnchorElement>): ReactNode;
91
91
  }
@@ -3,9 +3,9 @@ import { LinkOptions, NavigateOptions } from './link';
3
3
  import { AnyRoute } from './route';
4
4
  import { RoutePaths } from './routeInfo';
5
5
  import { RegisteredRouter } from './router';
6
- export declare function useNavigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDefaultFrom extends RoutePaths<TRouteTree> = '/'>(defaultOpts?: {
6
+ export declare function useNavigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDefaultFrom extends RoutePaths<TRouteTree> = '/'>(_defaultOpts?: {
7
7
  from?: TDefaultFrom;
8
- }): <TFrom extends RoutePaths<TRouteTree> = TDefaultFrom, TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = "/", TMaskTo extends string = "">(opts?: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> | undefined) => Promise<void>;
8
+ }): <TFrom extends RoutePaths<TRouteTree> = TDefaultFrom, TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = "/", TMaskTo extends string = "">({ from, ...rest }: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>;
9
9
  export declare function Navigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): null;
10
10
  export type UseLinkPropsOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>;
11
11
  export type LinkProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
@@ -93,13 +93,15 @@
93
93
  push: (path, state) => {
94
94
  state = assignKey(state);
95
95
  tryNavigation(() => {
96
- opts.pushState(path, state, onUpdate);
96
+ opts.pushState(path, state);
97
+ onUpdate();
97
98
  });
98
99
  },
99
100
  replace: (path, state) => {
100
101
  state = assignKey(state);
101
102
  tryNavigation(() => {
102
- opts.replaceState(path, state, onUpdate);
103
+ opts.replaceState(path, state);
104
+ onUpdate();
103
105
  });
104
106
  },
105
107
  go: index => {
@@ -204,7 +206,7 @@
204
206
  };
205
207
 
206
208
  // This function queues up a call to update the browser history
207
- const queueHistoryAction = (type, destHref, state, onUpdate) => {
209
+ const queueHistoryAction = (type, destHref, state) => {
208
210
  const href = createHref(destHref);
209
211
  if (!scheduled) {
210
212
  rollbackLocation = currentLocation;
@@ -219,9 +221,6 @@
219
221
  state,
220
222
  isPush: next?.isPush || type === 'push'
221
223
  };
222
-
223
- // Notify subscribers
224
- onUpdate();
225
224
  if (!scheduled) {
226
225
  // Schedule an update to the browser history
227
226
  scheduled = Promise.resolve().then(() => flush());
@@ -235,8 +234,8 @@
235
234
  var originalReplaceState = win.history.replaceState;
236
235
  const history = createHistory({
237
236
  getLocation,
238
- pushState: (href, state, onUpdate) => queueHistoryAction('push', href, state, onUpdate),
239
- replaceState: (href, state, onUpdate) => queueHistoryAction('replace', href, state, onUpdate),
237
+ pushState: (href, state) => queueHistoryAction('push', href, state),
238
+ replaceState: (href, state) => queueHistoryAction('replace', href, state),
240
239
  back: () => win.history.back(),
241
240
  forward: () => win.history.forward(),
242
241
  go: n => win.history.go(n),
@@ -1688,7 +1687,10 @@
1688
1687
  }
1689
1688
 
1690
1689
  const preloadWarning = 'Error preloading route! ☝️';
1691
- function useLinkProps(options) {
1690
+ function useLinkProps({
1691
+ from,
1692
+ ...options
1693
+ }) {
1692
1694
  const router = useRouter();
1693
1695
  const matchPathname = useMatch({
1694
1696
  strict: false,
@@ -2510,7 +2512,7 @@
2510
2512
  };
2511
2513
  navigate = ({
2512
2514
  from,
2513
- to = '',
2515
+ to,
2514
2516
  ...rest
2515
2517
  }) => {
2516
2518
  // If this link simply reloads the current route,
@@ -2519,7 +2521,7 @@
2519
2521
  // If this `to` is a valid external URL, return
2520
2522
  // null for LinkUtils
2521
2523
  const toString = String(to);
2522
- const fromString = typeof from === 'undefined' ? from : String(from);
2524
+ // const fromString = from !== undefined ? String(from) : from
2523
2525
  let isExternal;
2524
2526
  try {
2525
2527
  new URL(`${toString}`);
@@ -2528,8 +2530,9 @@
2528
2530
  invariant(!isExternal, 'Attempting to navigate to external url with this.navigate!');
2529
2531
  return this.buildAndCommitLocation({
2530
2532
  ...rest,
2531
- from: fromString,
2532
- to: toString
2533
+ from,
2534
+ to
2535
+ // to: toString,
2533
2536
  });
2534
2537
  };
2535
2538
  loadMatches = async ({
@@ -3231,19 +3234,22 @@
3231
3234
  return children ?? null;
3232
3235
  }
3233
3236
 
3234
- function useNavigate(defaultOpts) {
3237
+ function useNavigate(_defaultOpts) {
3235
3238
  const {
3236
- navigate
3239
+ navigate,
3240
+ buildLocation
3237
3241
  } = useRouter();
3238
3242
  const matchPathname = useMatch({
3239
3243
  strict: false,
3240
3244
  select: s => s.pathname
3241
3245
  });
3242
- return React__namespace.useCallback(opts => {
3246
+ return React__namespace.useCallback(({
3247
+ from,
3248
+ ...rest
3249
+ }) => {
3243
3250
  return navigate({
3244
- from: opts?.to ? matchPathname : undefined,
3245
- ...defaultOpts,
3246
- ...opts
3251
+ from: rest?.to ? matchPathname : undefined,
3252
+ ...rest
3247
3253
  });
3248
3254
  }, []);
3249
3255
  }