@tanstack/react-router 0.0.1-beta.250 → 0.0.1-beta.251
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/router.js +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +357 -357
- package/build/umd/index.development.js +20 -15
- 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/router.ts +1 -1
|
@@ -167,9 +167,9 @@
|
|
|
167
167
|
*/
|
|
168
168
|
function createBrowserHistory(opts) {
|
|
169
169
|
const win = opts?.window ?? (typeof document !== 'undefined' ? window : undefined);
|
|
170
|
-
const getHref = opts?.getHref ?? (() => `${win.location.pathname}${win.location.search}${win.location.hash}`);
|
|
171
170
|
const createHref = opts?.createHref ?? (path => path);
|
|
172
|
-
|
|
171
|
+
const parseLocation = opts?.parseLocation ?? (() => parseHref(`${win.location.pathname}${win.location.search}${win.location.hash}`, win.history.state));
|
|
172
|
+
let currentLocation = parseLocation();
|
|
173
173
|
let rollbackLocation;
|
|
174
174
|
const getLocation = () => currentLocation;
|
|
175
175
|
let next;
|
|
@@ -206,14 +206,15 @@
|
|
|
206
206
|
};
|
|
207
207
|
|
|
208
208
|
// This function queues up a call to update the browser history
|
|
209
|
-
const queueHistoryAction = (type,
|
|
210
|
-
|
|
209
|
+
const queueHistoryAction = (type, destHref, state, onUpdate) => {
|
|
210
|
+
console.log(destHref);
|
|
211
|
+
const href = createHref(destHref);
|
|
211
212
|
if (!scheduled) {
|
|
212
213
|
rollbackLocation = currentLocation;
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
// Update the location in memory
|
|
216
|
-
currentLocation =
|
|
217
|
+
currentLocation = parseHref(destHref, state);
|
|
217
218
|
|
|
218
219
|
// Keep track of the next location we need to flush to the URL
|
|
219
220
|
next = {
|
|
@@ -230,19 +231,19 @@
|
|
|
230
231
|
}
|
|
231
232
|
};
|
|
232
233
|
const onPushPop = () => {
|
|
233
|
-
currentLocation = parseLocation(
|
|
234
|
+
currentLocation = parseLocation();
|
|
234
235
|
history.notify();
|
|
235
236
|
};
|
|
236
237
|
var originalPushState = win.history.pushState;
|
|
237
238
|
var originalReplaceState = win.history.replaceState;
|
|
238
239
|
const history = createHistory({
|
|
239
240
|
getLocation,
|
|
240
|
-
pushState: (
|
|
241
|
-
replaceState: (
|
|
241
|
+
pushState: (href, state, onUpdate) => queueHistoryAction('push', href, state, onUpdate),
|
|
242
|
+
replaceState: (href, state, onUpdate) => queueHistoryAction('replace', href, state, onUpdate),
|
|
242
243
|
back: () => win.history.back(),
|
|
243
244
|
forward: () => win.history.forward(),
|
|
244
245
|
go: n => win.history.go(n),
|
|
245
|
-
createHref:
|
|
246
|
+
createHref: href => createHref(href),
|
|
246
247
|
flush,
|
|
247
248
|
destroy: () => {
|
|
248
249
|
win.history.pushState = originalPushState;
|
|
@@ -277,9 +278,13 @@
|
|
|
277
278
|
function createHashHistory(opts) {
|
|
278
279
|
const win = opts?.window ?? (typeof document !== 'undefined' ? window : undefined);
|
|
279
280
|
return createBrowserHistory({
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
window: win,
|
|
282
|
+
parseLocation: () => {
|
|
283
|
+
const hashHref = win.location.hash.split('#').slice(1).join('#') ?? '/';
|
|
284
|
+
console.log(hashHref);
|
|
285
|
+
return parseHref(hashHref, win.history.state);
|
|
286
|
+
},
|
|
287
|
+
createHref: href => `${win.location.pathname}${win.location.search}#${href}`
|
|
283
288
|
});
|
|
284
289
|
}
|
|
285
290
|
function createMemoryHistory(opts = {
|
|
@@ -290,7 +295,7 @@
|
|
|
290
295
|
let currentState = {
|
|
291
296
|
key: createRandomKey()
|
|
292
297
|
};
|
|
293
|
-
const getLocation = () =>
|
|
298
|
+
const getLocation = () => parseHref(entries[index], currentState);
|
|
294
299
|
return createHistory({
|
|
295
300
|
getLocation,
|
|
296
301
|
pushState: (path, state) => {
|
|
@@ -314,7 +319,7 @@
|
|
|
314
319
|
createHref: path => path
|
|
315
320
|
});
|
|
316
321
|
}
|
|
317
|
-
function
|
|
322
|
+
function parseHref(href, state) {
|
|
318
323
|
let hashIndex = href.indexOf('#');
|
|
319
324
|
let searchIndex = href.indexOf('?');
|
|
320
325
|
return {
|
|
@@ -2262,7 +2267,7 @@
|
|
|
2262
2267
|
searchStr,
|
|
2263
2268
|
state: nextState,
|
|
2264
2269
|
hash,
|
|
2265
|
-
href:
|
|
2270
|
+
href: `${pathname}${searchStr}${hashStr}`,
|
|
2266
2271
|
unmaskOnReload: dest.unmaskOnReload
|
|
2267
2272
|
};
|
|
2268
2273
|
};
|