@tanstack/react-router 0.0.1-beta.248 → 0.0.1-beta.249

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.
@@ -69,7 +69,7 @@
69
69
  subscribers.forEach(subscriber => subscriber());
70
70
  };
71
71
  const tryNavigation = task => {
72
- if (blockers.length) {
72
+ if (typeof document !== 'undefined' && blockers.length) {
73
73
  for (let blocker of blockers) {
74
74
  if (!window.confirm(blocker.message)) {
75
75
  opts.onBlocked?.(onUpdate);
@@ -166,9 +166,10 @@
166
166
  * @returns A history instance
167
167
  */
168
168
  function createBrowserHistory(opts) {
169
- const getHref = opts?.getHref ?? (() => `${window.location.pathname}${window.location.search}${window.location.hash}`);
169
+ const win = opts?.window ?? (typeof document !== 'undefined' ? window : undefined);
170
+ const getHref = opts?.getHref ?? (() => `${win.location.pathname}${win.location.search}${win.location.hash}`);
170
171
  const createHref = opts?.createHref ?? (path => path);
171
- let currentLocation = parseLocation(getHref(), window.history.state);
172
+ let currentLocation = parseLocation(getHref(), win.history.state);
172
173
  let rollbackLocation;
173
174
  const getLocation = () => currentLocation;
174
175
  let next;
@@ -196,7 +197,7 @@
196
197
  // Do not notify subscribers about this push/replace call
197
198
  untrack(() => {
198
199
  if (!next) return;
199
- window.history[next.isPush ? 'pushState' : 'replaceState'](next.state, '', next.href);
200
+ win.history[next.isPush ? 'pushState' : 'replaceState'](next.state, '', next.href);
200
201
  // Reset the nextIsPush flag and clear the scheduled update
201
202
  next = undefined;
202
203
  scheduled = undefined;
@@ -229,25 +230,25 @@
229
230
  }
230
231
  };
231
232
  const onPushPop = () => {
232
- currentLocation = parseLocation(getHref(), window.history.state);
233
+ currentLocation = parseLocation(getHref(), win.history.state);
233
234
  history.notify();
234
235
  };
235
- var originalPushState = window.history.pushState;
236
- var originalReplaceState = window.history.replaceState;
236
+ var originalPushState = win.history.pushState;
237
+ var originalReplaceState = win.history.replaceState;
237
238
  const history = createHistory({
238
239
  getLocation,
239
240
  pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate),
240
241
  replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate),
241
- back: () => window.history.back(),
242
- forward: () => window.history.forward(),
243
- go: n => window.history.go(n),
242
+ back: () => win.history.back(),
243
+ forward: () => win.history.forward(),
244
+ go: n => win.history.go(n),
244
245
  createHref: path => createHref(path),
245
246
  flush,
246
247
  destroy: () => {
247
- window.history.pushState = originalPushState;
248
- window.history.replaceState = originalReplaceState;
249
- window.removeEventListener(pushStateEvent, onPushPop);
250
- window.removeEventListener(popStateEvent, onPushPop);
248
+ win.history.pushState = originalPushState;
249
+ win.history.replaceState = originalReplaceState;
250
+ win.removeEventListener(pushStateEvent, onPushPop);
251
+ win.removeEventListener(popStateEvent, onPushPop);
251
252
  },
252
253
  onBlocked: onUpdate => {
253
254
  // If a navigation is blocked, we need to rollback the location
@@ -259,24 +260,27 @@
259
260
  }
260
261
  }
261
262
  });
262
- window.addEventListener(pushStateEvent, onPushPop);
263
- window.addEventListener(popStateEvent, onPushPop);
264
- window.history.pushState = function () {
265
- let res = originalPushState.apply(window.history, arguments);
263
+ win.addEventListener(pushStateEvent, onPushPop);
264
+ win.addEventListener(popStateEvent, onPushPop);
265
+ win.history.pushState = function () {
266
+ let res = originalPushState.apply(win.history, arguments);
266
267
  if (tracking) history.notify();
267
268
  return res;
268
269
  };
269
- window.history.replaceState = function () {
270
- let res = originalReplaceState.apply(window.history, arguments);
270
+ win.history.replaceState = function () {
271
+ let res = originalReplaceState.apply(win.history, arguments);
271
272
  if (tracking) history.notify();
272
273
  return res;
273
274
  };
274
275
  return history;
275
276
  }
276
- function createHashHistory() {
277
+ function createHashHistory({
278
+ window: win
279
+ }) {
277
280
  return createBrowserHistory({
278
- getHref: () => window.location.hash.substring(1),
279
- createHref: path => `#${path}`
281
+ getHref: () => win.location.hash.substring(1),
282
+ createHref: path => `#${path}`,
283
+ window: win
280
284
  });
281
285
  }
282
286
  function createMemoryHistory(opts = {
@@ -305,7 +309,9 @@
305
309
  forward: () => {
306
310
  index = Math.min(index + 1, entries.length - 1);
307
311
  },
308
- go: n => window.history.go(n),
312
+ go: n => {
313
+ index = Math.min(Math.max(index + n, 0), entries.length - 1);
314
+ },
309
315
  createHref: path => path
310
316
  });
311
317
  }
@@ -2795,10 +2801,12 @@
2795
2801
  }
2796
2802
  };
2797
2803
  const handleTouchStart = e => {
2798
- this.preloadRoute(nextOpts).catch(err => {
2799
- console.warn(err);
2800
- console.warn(preloadWarning);
2801
- });
2804
+ if (preload) {
2805
+ this.preloadRoute(nextOpts).catch(err => {
2806
+ console.warn(err);
2807
+ console.warn(preloadWarning);
2808
+ });
2809
+ }
2802
2810
  };
2803
2811
  const handleEnter = e => {
2804
2812
  const target = e.target || {};
@@ -3200,6 +3208,7 @@
3200
3208
  exports.componentTypes = componentTypes;
3201
3209
  exports.createBrowserHistory = createBrowserHistory;
3202
3210
  exports.createHashHistory = createHashHistory;
3211
+ exports.createHistory = createHistory;
3203
3212
  exports.createMemoryHistory = createMemoryHistory;
3204
3213
  exports.createRouteMask = createRouteMask;
3205
3214
  exports.decode = decode;