@tanstack/router-core 0.0.1-alpha.8 → 0.0.1-beta.1

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.
@@ -35,13 +35,15 @@ function createRouter(userOptions) {
35
35
  const originalOptions = _rollupPluginBabelHelpers["extends"]({
36
36
  defaultLoaderGcMaxAge: 5 * 60 * 1000,
37
37
  defaultLoaderMaxAge: 0,
38
- defaultLinkPreloadDelay: 50
38
+ defaultPreloadMaxAge: 2000,
39
+ defaultPreloadDelay: 50
39
40
  }, userOptions, {
40
41
  stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : searchParams.defaultStringifySearch,
41
42
  parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : searchParams.defaultParseSearch
42
43
  });
43
44
 
44
45
  let router = {
46
+ history,
45
47
  options: originalOptions,
46
48
  listeners: [],
47
49
  removeActionQueue: [],
@@ -60,6 +62,7 @@ function createRouter(userOptions) {
60
62
  location: null,
61
63
  matches: [],
62
64
  actions: {},
65
+ loaders: {},
63
66
  loaderData: {},
64
67
  lastUpdated: Date.now(),
65
68
  isFetching: false,
@@ -84,21 +87,22 @@ function createRouter(userOptions) {
84
87
  router.listeners.forEach(listener => listener());
85
88
  },
86
89
  mount: () => {
87
- const next = router.buildLocation({
90
+ const next = router.__.buildLocation({
88
91
  to: '.',
89
92
  search: true,
90
93
  hash: true
91
94
  }); // If the current location isn't updated, trigger a navigation
92
95
  // to the current location. Otherwise, load the current location.
93
96
 
97
+
94
98
  if (next.href !== router.location.href) {
95
- router.commitLocation(next, true);
99
+ router.__.commitLocation(next, true);
96
100
  } else {
97
101
  router.loadLocation();
98
102
  }
99
103
 
100
104
  const unsub = history.listen(event => {
101
- router.loadLocation(router.parseLocation(event.location, router.location));
105
+ router.loadLocation(router.__.parseLocation(event.location, router.location));
102
106
  }); // addEventListener does not exist in React Native, but window does
103
107
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
104
108
 
@@ -128,169 +132,11 @@ function createRouter(userOptions) {
128
132
 
129
133
  if (routeConfig) {
130
134
  router.routesById = {};
131
- router.routeTree = router.buildRouteTree(routeConfig);
135
+ router.routeTree = router.__.buildRouteTree(routeConfig);
132
136
  }
133
137
 
134
138
  return router;
135
139
  },
136
- buildRouteTree: rootRouteConfig => {
137
- const recurseRoutes = (routeConfigs, parent) => {
138
- return routeConfigs.map(routeConfig => {
139
- const routeOptions = routeConfig.options;
140
- const route$1 = route.createRoute(routeConfig, routeOptions, parent, router); // {
141
- // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
142
- // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
143
- // }
144
-
145
- const existingRoute = router.routesById[route$1.routeId];
146
-
147
- if (existingRoute) {
148
- if (process.env.NODE_ENV !== 'production') {
149
- console.warn("Duplicate routes found with id: " + String(route$1.routeId), router.routesById, route$1);
150
- }
151
-
152
- throw new Error();
153
- }
154
- router.routesById[route$1.routeId] = route$1;
155
- const children = routeConfig.children;
156
- route$1.childRoutes = children != null && children.length ? recurseRoutes(children, route$1) : undefined;
157
- return route$1;
158
- });
159
- };
160
-
161
- const routes = recurseRoutes([rootRouteConfig]);
162
- return routes[0];
163
- },
164
- parseLocation: (location, previousLocation) => {
165
- var _location$hash$split$;
166
-
167
- const parsedSearch = router.options.parseSearch(location.search);
168
- return {
169
- pathname: location.pathname,
170
- searchStr: location.search,
171
- search: utils.replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
172
- hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
173
- href: "" + location.pathname + location.search + location.hash,
174
- state: location.state,
175
- key: location.key
176
- };
177
- },
178
- buildLocation: function buildLocation(dest) {
179
- var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
180
-
181
- if (dest === void 0) {
182
- dest = {};
183
- }
184
-
185
- // const resolvedFrom: Location = {
186
- // ...router.location,
187
- const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
188
-
189
- let pathname = path.resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
190
-
191
- const fromMatches = router.matchRoutes(router.location.pathname, {
192
- strictParseParams: true
193
- });
194
- const toMatches = router.matchRoutes(pathname);
195
-
196
- const prevParams = _rollupPluginBabelHelpers["extends"]({}, (_last = utils.last(fromMatches)) == null ? void 0 : _last.params);
197
-
198
- let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : utils.functionalUpdate(dest.params, prevParams);
199
-
200
- if (nextParams) {
201
- toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
202
- Object.assign({}, nextParams, fn(nextParams));
203
- });
204
- }
205
-
206
- pathname = path.interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
207
-
208
- const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
209
-
210
- const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
211
- : dest.search ? (_functionalUpdate = utils.functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
212
- : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
213
- : {}; // Then post filters
214
-
215
- const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
216
- const search = utils.replaceEqualDeep(router.location.search, postFilteredSearch);
217
- const searchStr = router.options.stringifySearch(search);
218
- let hash = dest.hash === true ? router.location.hash : utils.functionalUpdate(dest.hash, router.location.hash);
219
- hash = hash ? "#" + hash : '';
220
- return {
221
- pathname,
222
- search,
223
- searchStr,
224
- state: router.location.state,
225
- hash,
226
- href: "" + pathname + searchStr + hash,
227
- key: dest.key
228
- };
229
- },
230
- commitLocation: (next, replace) => {
231
- const id = '' + Date.now() + Math.random();
232
- if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
233
- let nextAction = 'replace';
234
-
235
- if (!replace) {
236
- nextAction = 'push';
237
- }
238
-
239
- const isSameUrl = router.parseLocation(history.location).href === next.href;
240
-
241
- if (isSameUrl && !next.key) {
242
- nextAction = 'replace';
243
- }
244
-
245
- if (nextAction === 'replace') {
246
- history.replace({
247
- pathname: next.pathname,
248
- hash: next.hash,
249
- search: next.searchStr
250
- }, {
251
- id
252
- });
253
- } else {
254
- history.push({
255
- pathname: next.pathname,
256
- hash: next.hash,
257
- search: next.searchStr
258
- }, {
259
- id
260
- });
261
- }
262
-
263
- router.navigationPromise = new Promise(resolve => {
264
- const previousNavigationResolve = router.resolveNavigation;
265
-
266
- router.resolveNavigation = () => {
267
- previousNavigationResolve();
268
- resolve();
269
- };
270
- });
271
- return router.navigationPromise;
272
- },
273
- buildNext: opts => {
274
- const next = router.buildLocation(opts);
275
- const matches = router.matchRoutes(next.pathname);
276
-
277
- const __preSearchFilters = matches.map(match => {
278
- var _match$options$preSea;
279
-
280
- return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
281
- }).flat().filter(Boolean);
282
-
283
- const __postSearchFilters = matches.map(match => {
284
- var _match$options$postSe;
285
-
286
- return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
287
- }).flat().filter(Boolean);
288
-
289
- return router.buildLocation(_rollupPluginBabelHelpers["extends"]({}, opts, {
290
- __preSearchFilters,
291
- __postSearchFilters
292
- }));
293
- },
294
140
  cancelMatches: () => {
295
141
  var _router$state$pending, _router$state$pending2;
296
142
  [...router.state.matches, ...((_router$state$pending = (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches) != null ? _router$state$pending : [])].forEach(match => {
@@ -393,6 +239,7 @@ function createRouter(userOptions) {
393
239
  params: d.params,
394
240
  search: d.search
395
241
  });
242
+ delete router.matchCache[d.matchId];
396
243
  });
397
244
 
398
245
  if (matches.some(d => d.status === 'loading')) {
@@ -432,7 +279,21 @@ function createRouter(userOptions) {
432
279
  delete router.matchCache[matchId];
433
280
  });
434
281
  },
435
- loadRoute: async function loadRoute(navigateOpts, loaderOpts) {
282
+ loadRoute: async function loadRoute(navigateOpts) {
283
+ if (navigateOpts === void 0) {
284
+ navigateOpts = router.location;
285
+ }
286
+
287
+ const next = router.buildNext(navigateOpts);
288
+ const matches = router.matchRoutes(next.pathname, {
289
+ strictParseParams: true
290
+ });
291
+ await router.loadMatches(matches);
292
+ return matches;
293
+ },
294
+ preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
295
+ var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
296
+
436
297
  if (navigateOpts === void 0) {
437
298
  navigateOpts = router.location;
438
299
  }
@@ -443,7 +304,8 @@ function createRouter(userOptions) {
443
304
  });
444
305
  await router.loadMatches(matches, {
445
306
  preload: true,
446
- maxAge: loaderOpts.maxAge
307
+ maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
308
+ gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
447
309
  });
448
310
  return matches;
449
311
  },
@@ -537,33 +399,11 @@ function createRouter(userOptions) {
537
399
  return matches;
538
400
  },
539
401
  loadMatches: async (resolvedMatches, loaderOpts) => {
540
- const now = Date.now();
541
402
  const matchPromises = resolvedMatches.map(async match => {
542
403
  // Validate the match (loads search params etc)
543
- match.__.validate(); // // If the match doesn't have a loader, don't attempt to load it
544
- // if (!match.hasLoaders()) {
545
- // return
546
- // }
547
- // If this is a preload, add it to the preload cache
548
-
549
-
550
- if (loaderOpts != null && loaderOpts.preload && (loaderOpts == null ? void 0 : loaderOpts.maxAge) > 0) {
551
- // If the match is currently active, don't preload it
552
- if (router.state.matches.find(d => d.matchId === match.matchId)) {
553
- return;
554
- }
555
-
556
- router.matchCache[match.matchId] = {
557
- gc: now + loaderOpts.maxAge,
558
- // TODO: Should this use the route's maxAge?
559
- match
560
- };
561
- } // If the match is invalid, errored or idle, trigger it to load
404
+ match.__.validate();
562
405
 
563
-
564
- if (match.status === 'success' && match.getIsInvalid() || match.status === 'error' || match.status === 'idle') {
565
- match.load();
566
- }
406
+ match.load(loaderOpts);
567
407
 
568
408
  if (match.status === 'loading') {
569
409
  // If requested, start the pending timers
@@ -587,7 +427,7 @@ function createRouter(userOptions) {
587
427
  }
588
428
  });
589
429
  },
590
- reload: () => router._navigate({
430
+ reload: () => router.__.navigate({
591
431
  fromCurrent: true,
592
432
  replace: true,
593
433
  search: true
@@ -620,11 +460,7 @@ function createRouter(userOptions) {
620
460
  to: next.pathname
621
461
  }));
622
462
  },
623
- _navigate: location => {
624
- const next = router.buildNext(location);
625
- return router.commitLocation(next, location.replace);
626
- },
627
- navigate: async _ref4 => {
463
+ navigate: async _ref8 => {
628
464
  let {
629
465
  from,
630
466
  to = '.',
@@ -632,7 +468,7 @@ function createRouter(userOptions) {
632
468
  hash,
633
469
  replace,
634
470
  params
635
- } = _ref4;
471
+ } = _ref8;
636
472
  // If this link simply reloads the current route,
637
473
  // make sure it has a new key so it will trigger a data refresh
638
474
  // If this `to` is a valid external URL, return
@@ -647,7 +483,7 @@ function createRouter(userOptions) {
647
483
  } catch (e) {}
648
484
 
649
485
  tinyInvariant["default"](!isExternal, 'Attempting to navigate to external url with router.navigate!');
650
- return router._navigate({
486
+ return router.__.navigate({
651
487
  from: fromString,
652
488
  to: toString,
653
489
  search,
@@ -656,8 +492,8 @@ function createRouter(userOptions) {
656
492
  params
657
493
  });
658
494
  },
659
- buildLink: _ref5 => {
660
- var _preload, _ref6, _ref7, _ref8;
495
+ buildLink: _ref9 => {
496
+ var _preload, _ref10;
661
497
 
662
498
  let {
663
499
  from,
@@ -670,9 +506,10 @@ function createRouter(userOptions) {
670
506
  activeOptions,
671
507
  preload,
672
508
  preloadMaxAge: userPreloadMaxAge,
509
+ preloadGcMaxAge: userPreloadGcMaxAge,
673
510
  preloadDelay: userPreloadDelay,
674
511
  disabled
675
- } = _ref5;
512
+ } = _ref9;
676
513
 
677
514
  // If this link simply reloads the current route,
678
515
  // make sure it has a new key so it will trigger a data refresh
@@ -695,9 +532,8 @@ function createRouter(userOptions) {
695
532
  replace
696
533
  };
697
534
  const next = router.buildNext(nextOpts);
698
- preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
699
- const preloadMaxAge = (_ref6 = (_ref7 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0;
700
- const preloadDelay = (_ref8 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref8 : 0; // Compare path/hash for matches
535
+ preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
536
+ const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
701
537
 
702
538
  const pathIsEqual = router.state.location.pathname === next.pathname;
703
539
  const currentPathSplit = router.state.location.pathname.split('/');
@@ -719,15 +555,16 @@ function createRouter(userOptions) {
719
555
  } // All is well? Navigate!)
720
556
 
721
557
 
722
- router._navigate(nextOpts);
558
+ router.__.navigate(nextOpts);
723
559
  }
724
560
  }; // The click handler
725
561
 
726
562
 
727
563
  const handleFocus = e => {
728
- if (preload && preloadMaxAge > 0) {
729
- router.loadRoute(nextOpts, {
730
- maxAge: preloadMaxAge
564
+ if (preload) {
565
+ router.preloadRoute(nextOpts, {
566
+ maxAge: userPreloadMaxAge,
567
+ gcMaxAge: userPreloadGcMaxAge
731
568
  });
732
569
  }
733
570
  };
@@ -735,15 +572,16 @@ function createRouter(userOptions) {
735
572
  const handleEnter = e => {
736
573
  const target = e.target || {};
737
574
 
738
- if (preload && preloadMaxAge > 0) {
575
+ if (preload) {
739
576
  if (target.preloadTimeout) {
740
577
  return;
741
578
  }
742
579
 
743
580
  target.preloadTimeout = setTimeout(() => {
744
581
  target.preloadTimeout = null;
745
- router.loadRoute(nextOpts, {
746
- maxAge: preloadMaxAge
582
+ router.preloadRoute(nextOpts, {
583
+ maxAge: userPreloadMaxAge,
584
+ gcMaxAge: userPreloadGcMaxAge
747
585
  });
748
586
  }, preloadDelay);
749
587
  }
@@ -768,9 +606,174 @@ function createRouter(userOptions) {
768
606
  isActive,
769
607
  disabled
770
608
  };
609
+ },
610
+ buildNext: opts => {
611
+ const next = router.__.buildLocation(opts);
612
+
613
+ const matches = router.matchRoutes(next.pathname);
614
+
615
+ const __preSearchFilters = matches.map(match => {
616
+ var _match$options$preSea;
617
+
618
+ return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
619
+ }).flat().filter(Boolean);
620
+
621
+ const __postSearchFilters = matches.map(match => {
622
+ var _match$options$postSe;
623
+
624
+ return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
625
+ }).flat().filter(Boolean);
626
+
627
+ return router.__.buildLocation(_rollupPluginBabelHelpers["extends"]({}, opts, {
628
+ __preSearchFilters,
629
+ __postSearchFilters
630
+ }));
631
+ },
632
+ __: {
633
+ buildRouteTree: rootRouteConfig => {
634
+ const recurseRoutes = (routeConfigs, parent) => {
635
+ return routeConfigs.map(routeConfig => {
636
+ const routeOptions = routeConfig.options;
637
+ const route$1 = route.createRoute(routeConfig, routeOptions, parent, router); // {
638
+ // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
639
+ // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
640
+ // }
641
+
642
+ const existingRoute = router.routesById[route$1.routeId];
643
+
644
+ if (existingRoute) {
645
+ if (process.env.NODE_ENV !== 'production') {
646
+ console.warn("Duplicate routes found with id: " + String(route$1.routeId), router.routesById, route$1);
647
+ }
648
+
649
+ throw new Error();
650
+ }
651
+ router.routesById[route$1.routeId] = route$1;
652
+ const children = routeConfig.children;
653
+ route$1.childRoutes = children != null && children.length ? recurseRoutes(children, route$1) : undefined;
654
+ return route$1;
655
+ });
656
+ };
657
+
658
+ const routes = recurseRoutes([rootRouteConfig]);
659
+ return routes[0];
660
+ },
661
+ parseLocation: (location, previousLocation) => {
662
+ var _location$hash$split$;
663
+
664
+ const parsedSearch = router.options.parseSearch(location.search);
665
+ return {
666
+ pathname: location.pathname,
667
+ searchStr: location.search,
668
+ search: utils.replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
669
+ hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
670
+ href: "" + location.pathname + location.search + location.hash,
671
+ state: location.state,
672
+ key: location.key
673
+ };
674
+ },
675
+ navigate: location => {
676
+ const next = router.buildNext(location);
677
+ return router.__.commitLocation(next, location.replace);
678
+ },
679
+ buildLocation: function buildLocation(dest) {
680
+ var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
681
+
682
+ if (dest === void 0) {
683
+ dest = {};
684
+ }
685
+
686
+ // const resolvedFrom: Location = {
687
+ // ...router.location,
688
+ const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
689
+
690
+ let pathname = path.resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
691
+
692
+ const fromMatches = router.matchRoutes(router.location.pathname, {
693
+ strictParseParams: true
694
+ });
695
+ const toMatches = router.matchRoutes(pathname);
696
+
697
+ const prevParams = _rollupPluginBabelHelpers["extends"]({}, (_last = utils.last(fromMatches)) == null ? void 0 : _last.params);
698
+
699
+ let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : utils.functionalUpdate(dest.params, prevParams);
700
+
701
+ if (nextParams) {
702
+ toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
703
+ Object.assign({}, nextParams, fn(nextParams));
704
+ });
705
+ }
706
+
707
+ pathname = path.interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
708
+
709
+ const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
710
+
711
+ const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
712
+ : dest.search ? (_functionalUpdate = utils.functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
713
+ : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
714
+ : {}; // Then post filters
715
+
716
+ const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
717
+ const search = utils.replaceEqualDeep(router.location.search, postFilteredSearch);
718
+ const searchStr = router.options.stringifySearch(search);
719
+ let hash = dest.hash === true ? router.location.hash : utils.functionalUpdate(dest.hash, router.location.hash);
720
+ hash = hash ? "#" + hash : '';
721
+ return {
722
+ pathname,
723
+ search,
724
+ searchStr,
725
+ state: router.location.state,
726
+ hash,
727
+ href: "" + pathname + searchStr + hash,
728
+ key: dest.key
729
+ };
730
+ },
731
+ commitLocation: (next, replace) => {
732
+ const id = '' + Date.now() + Math.random();
733
+ if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
734
+ let nextAction = 'replace';
735
+
736
+ if (!replace) {
737
+ nextAction = 'push';
738
+ }
739
+
740
+ const isSameUrl = router.__.parseLocation(history.location).href === next.href;
741
+
742
+ if (isSameUrl && !next.key) {
743
+ nextAction = 'replace';
744
+ }
745
+
746
+ if (nextAction === 'replace') {
747
+ history.replace({
748
+ pathname: next.pathname,
749
+ hash: next.hash,
750
+ search: next.searchStr
751
+ }, {
752
+ id
753
+ });
754
+ } else {
755
+ history.push({
756
+ pathname: next.pathname,
757
+ hash: next.hash,
758
+ search: next.searchStr
759
+ }, {
760
+ id
761
+ });
762
+ }
763
+
764
+ router.navigationPromise = new Promise(resolve => {
765
+ const previousNavigationResolve = router.resolveNavigation;
766
+
767
+ router.resolveNavigation = () => {
768
+ previousNavigationResolve();
769
+ resolve();
770
+ };
771
+ });
772
+ return router.navigationPromise;
773
+ }
771
774
  }
772
775
  };
773
- router.location = router.parseLocation(history.location);
776
+ router.location = router.__.parseLocation(history.location);
774
777
  router.state.location = router.location;
775
778
  router.update(userOptions); // Allow frameworks to hook into the router creation
776
779