Skip to content

Commit 21da012

Browse files
committed
fix: fix hash history
1 parent a3a6ff9 commit 21da012

10 files changed

Lines changed: 51604 additions & 10518 deletions

dist/vue-router.common.js

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* vue-router v3.0.7
3-
* (c) 2019 Evan You
3+
* (c) 2022 Evan You
44
* @license MIT
55
*/
66
'use strict';
@@ -2450,7 +2450,11 @@ var HashHistory = /*@__PURE__*/(function (History$$1) {
24502450
if (!ensureSlash()) {
24512451
return
24522452
}
2453-
this$1.transitionTo(getHash(), function (route) {
2453+
var locations = [getHash()];
2454+
if (window.history && window.history.state && typeof window.history.state.state === 'object') {
2455+
locations = window.history.state.state;
2456+
}
2457+
this$1.transitionTo(locations, function (route) {
24542458
if (supportsScroll) {
24552459
handleScroll(this$1.router, route, current, true);
24562460
}
@@ -2461,38 +2465,52 @@ var HashHistory = /*@__PURE__*/(function (History$$1) {
24612465
});
24622466
};
24632467

2464-
HashHistory.prototype.push = function push (location, onComplete, onAbort) {
2468+
HashHistory.prototype.navigateAllLayers = function navigateAllLayers (locations, push, onComplete, onAbort) {
24652469
var this$1 = this;
24662470

24672471
var ref = this;
24682472
var fromRoute = ref.current;
2469-
this.transitionTo(location, function (route) {
2473+
this.transitionTo(locations, function (routes) {
2474+
var route = this$1.current[this$1.current.length - 1];
24702475
pushHash(route.fullPath);
24712476
handleScroll(this$1.router, route, fromRoute, false);
24722477
onComplete && onComplete(route);
24732478
}, onAbort);
24742479
};
24752480

2476-
HashHistory.prototype.replace = function replace (location, onComplete, onAbort) {
2477-
var this$1 = this;
2481+
HashHistory.prototype.navigateLastLayer = function navigateLastLayer (location, push, onComplete, onAbort) {
2482+
var locations = this.current.slice(0, -1).map(function (r) { return r.fullPath; }).concat( [location]
2483+
);
2484+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2485+
};
24782486

2479-
var ref = this;
2480-
var fromRoute = ref.current;
2481-
this.transitionTo(location, function (route) {
2482-
replaceHash(route.fullPath);
2483-
handleScroll(this$1.router, route, fromRoute, false);
2484-
onComplete && onComplete(route);
2485-
}, onAbort);
2487+
HashHistory.prototype.navigateLayer = function navigateLayer (layer, location, push, onComplete, onAbort) {
2488+
var locations = this.current.slice(0, layer).map(function (r) { return r.fullPath; }).concat( [location],
2489+
this.current.slice(layer + 1).map(function (r) { return r.fullPath; })
2490+
);
2491+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2492+
};
2493+
2494+
HashHistory.prototype.navigateAddLayer = function navigateAddLayer (location, push, onComplete, onAbort) {
2495+
var locations = this.current.map(function (r) { return r.fullPath; }).concat( [location]
2496+
);
2497+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2498+
};
2499+
2500+
HashHistory.prototype.navigateRemoveLayer = function navigateRemoveLayer (location, push, onComplete, onAbort) {
2501+
var locations = this.current.slice(0, -1).map(function (r) { return r.fullPath; });
2502+
this.navigateAllLayers(locations, push, onComplete, onAbort);
24862503
};
24872504

24882505
HashHistory.prototype.go = function go (n) {
24892506
window.history.go(n);
24902507
};
24912508

24922509
HashHistory.prototype.ensureURL = function ensureURL (push) {
2493-
var current = this.current.fullPath;
2494-
if (getHash() !== current) {
2495-
push ? pushHash(current) : replaceHash(current);
2510+
var route = this.current[this.current.length - 1];
2511+
if (getHash() !== route.fullPath) {
2512+
var path = cleanPath(this.base + route.fullPath);
2513+
pushState(path, this.current.map(function (r) { return r.fullPath; }), !push);
24962514
}
24972515
};
24982516

@@ -2738,7 +2756,7 @@ VueRouter.prototype.init = function init (app /* Vue component instance */) {
27382756
history.setupListeners();
27392757
};
27402758
history.transitionTo(
2741-
history.getCurrentLocation(),
2759+
[history.getCurrentLocation()],
27422760
setupHashListener,
27432761
setupHashListener
27442762
);

dist/vue-router.esm.browser.js

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* vue-router v3.0.7
3-
* (c) 2019 Evan You
3+
* (c) 2022 Evan You
44
* @license MIT
55
*/
66
/* */
@@ -2419,7 +2419,11 @@ class HashHistory extends History {
24192419
if (!ensureSlash()) {
24202420
return
24212421
}
2422-
this.transitionTo(getHash(), route => {
2422+
let locations = [getHash()];
2423+
if (window.history && window.history.state && typeof window.history.state.state === 'object') {
2424+
locations = window.history.state.state;
2425+
}
2426+
this.transitionTo(locations, route => {
24232427
if (supportsScroll) {
24242428
handleScroll(this.router, route, current, true);
24252429
}
@@ -2430,32 +2434,55 @@ class HashHistory extends History {
24302434
});
24312435
}
24322436

2433-
push (location, onComplete, onAbort) {
2437+
navigateAllLayers (locations, push, onComplete, onAbort) {
24342438
const { current: fromRoute } = this;
2435-
this.transitionTo(location, route => {
2439+
this.transitionTo(locations, routes => {
2440+
const route = this.current[this.current.length - 1];
24362441
pushHash(route.fullPath);
24372442
handleScroll(this.router, route, fromRoute, false);
24382443
onComplete && onComplete(route);
24392444
}, onAbort);
24402445
}
24412446

2442-
replace (location, onComplete, onAbort) {
2443-
const { current: fromRoute } = this;
2444-
this.transitionTo(location, route => {
2445-
replaceHash(route.fullPath);
2446-
handleScroll(this.router, route, fromRoute, false);
2447-
onComplete && onComplete(route);
2448-
}, onAbort);
2447+
navigateLastLayer (location, push, onComplete, onAbort) {
2448+
const locations = [
2449+
...this.current.slice(0, -1).map(r => r.fullPath),
2450+
location
2451+
];
2452+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2453+
}
2454+
2455+
navigateLayer (layer, location, push, onComplete, onAbort) {
2456+
const locations = [
2457+
...this.current.slice(0, layer).map(r => r.fullPath),
2458+
location,
2459+
...this.current.slice(layer + 1).map(r => r.fullPath)
2460+
];
2461+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2462+
}
2463+
2464+
navigateAddLayer (location, push, onComplete, onAbort) {
2465+
const locations = [
2466+
...this.current.map(r => r.fullPath),
2467+
location
2468+
];
2469+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2470+
}
2471+
2472+
navigateRemoveLayer (location, push, onComplete, onAbort) {
2473+
const locations = this.current.slice(0, -1).map(r => r.fullPath);
2474+
this.navigateAllLayers(locations, push, onComplete, onAbort);
24492475
}
24502476

24512477
go (n) {
24522478
window.history.go(n);
24532479
}
24542480

24552481
ensureURL (push) {
2456-
const current = this.current.fullPath;
2457-
if (getHash() !== current) {
2458-
push ? pushHash(current) : replaceHash(current);
2482+
const route = this.current[this.current.length - 1];
2483+
if (getHash() !== route.fullPath) {
2484+
const path = cleanPath(this.base + route.fullPath);
2485+
pushState(path, this.current.map(r => r.fullPath), !push);
24592486
}
24602487
}
24612488

@@ -2701,7 +2728,7 @@ class VueRouter {
27012728
history.setupListeners();
27022729
};
27032730
history.transitionTo(
2704-
history.getCurrentLocation(),
2731+
[history.getCurrentLocation()],
27052732
setupHashListener,
27062733
setupHashListener
27072734
);

dist/vue-router.esm.browser.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-router.esm.js

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* vue-router v3.0.7
3-
* (c) 2019 Evan You
3+
* (c) 2022 Evan You
44
* @license MIT
55
*/
66
/* */
@@ -2448,7 +2448,11 @@ var HashHistory = /*@__PURE__*/(function (History$$1) {
24482448
if (!ensureSlash()) {
24492449
return
24502450
}
2451-
this$1.transitionTo(getHash(), function (route) {
2451+
var locations = [getHash()];
2452+
if (window.history && window.history.state && typeof window.history.state.state === 'object') {
2453+
locations = window.history.state.state;
2454+
}
2455+
this$1.transitionTo(locations, function (route) {
24522456
if (supportsScroll) {
24532457
handleScroll(this$1.router, route, current, true);
24542458
}
@@ -2459,38 +2463,52 @@ var HashHistory = /*@__PURE__*/(function (History$$1) {
24592463
});
24602464
};
24612465

2462-
HashHistory.prototype.push = function push (location, onComplete, onAbort) {
2466+
HashHistory.prototype.navigateAllLayers = function navigateAllLayers (locations, push, onComplete, onAbort) {
24632467
var this$1 = this;
24642468

24652469
var ref = this;
24662470
var fromRoute = ref.current;
2467-
this.transitionTo(location, function (route) {
2471+
this.transitionTo(locations, function (routes) {
2472+
var route = this$1.current[this$1.current.length - 1];
24682473
pushHash(route.fullPath);
24692474
handleScroll(this$1.router, route, fromRoute, false);
24702475
onComplete && onComplete(route);
24712476
}, onAbort);
24722477
};
24732478

2474-
HashHistory.prototype.replace = function replace (location, onComplete, onAbort) {
2475-
var this$1 = this;
2479+
HashHistory.prototype.navigateLastLayer = function navigateLastLayer (location, push, onComplete, onAbort) {
2480+
var locations = this.current.slice(0, -1).map(function (r) { return r.fullPath; }).concat( [location]
2481+
);
2482+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2483+
};
24762484

2477-
var ref = this;
2478-
var fromRoute = ref.current;
2479-
this.transitionTo(location, function (route) {
2480-
replaceHash(route.fullPath);
2481-
handleScroll(this$1.router, route, fromRoute, false);
2482-
onComplete && onComplete(route);
2483-
}, onAbort);
2485+
HashHistory.prototype.navigateLayer = function navigateLayer (layer, location, push, onComplete, onAbort) {
2486+
var locations = this.current.slice(0, layer).map(function (r) { return r.fullPath; }).concat( [location],
2487+
this.current.slice(layer + 1).map(function (r) { return r.fullPath; })
2488+
);
2489+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2490+
};
2491+
2492+
HashHistory.prototype.navigateAddLayer = function navigateAddLayer (location, push, onComplete, onAbort) {
2493+
var locations = this.current.map(function (r) { return r.fullPath; }).concat( [location]
2494+
);
2495+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2496+
};
2497+
2498+
HashHistory.prototype.navigateRemoveLayer = function navigateRemoveLayer (location, push, onComplete, onAbort) {
2499+
var locations = this.current.slice(0, -1).map(function (r) { return r.fullPath; });
2500+
this.navigateAllLayers(locations, push, onComplete, onAbort);
24842501
};
24852502

24862503
HashHistory.prototype.go = function go (n) {
24872504
window.history.go(n);
24882505
};
24892506

24902507
HashHistory.prototype.ensureURL = function ensureURL (push) {
2491-
var current = this.current.fullPath;
2492-
if (getHash() !== current) {
2493-
push ? pushHash(current) : replaceHash(current);
2508+
var route = this.current[this.current.length - 1];
2509+
if (getHash() !== route.fullPath) {
2510+
var path = cleanPath(this.base + route.fullPath);
2511+
pushState(path, this.current.map(function (r) { return r.fullPath; }), !push);
24942512
}
24952513
};
24962514

@@ -2736,7 +2754,7 @@ VueRouter.prototype.init = function init (app /* Vue component instance */) {
27362754
history.setupListeners();
27372755
};
27382756
history.transitionTo(
2739-
history.getCurrentLocation(),
2757+
[history.getCurrentLocation()],
27402758
setupHashListener,
27412759
setupHashListener
27422760
);

dist/vue-router.js

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* vue-router v3.0.7
3-
* (c) 2019 Evan You
3+
* (c) 2022 Evan You
44
* @license MIT
55
*/
66
(function (global, factory) {
@@ -2454,7 +2454,11 @@ var HashHistory = /*@__PURE__*/(function (History$$1) {
24542454
if (!ensureSlash()) {
24552455
return
24562456
}
2457-
this$1.transitionTo(getHash(), function (route) {
2457+
var locations = [getHash()];
2458+
if (window.history && window.history.state && typeof window.history.state.state === 'object') {
2459+
locations = window.history.state.state;
2460+
}
2461+
this$1.transitionTo(locations, function (route) {
24582462
if (supportsScroll) {
24592463
handleScroll(this$1.router, route, current, true);
24602464
}
@@ -2465,38 +2469,52 @@ var HashHistory = /*@__PURE__*/(function (History$$1) {
24652469
});
24662470
};
24672471

2468-
HashHistory.prototype.push = function push (location, onComplete, onAbort) {
2472+
HashHistory.prototype.navigateAllLayers = function navigateAllLayers (locations, push, onComplete, onAbort) {
24692473
var this$1 = this;
24702474

24712475
var ref = this;
24722476
var fromRoute = ref.current;
2473-
this.transitionTo(location, function (route) {
2477+
this.transitionTo(locations, function (routes) {
2478+
var route = this$1.current[this$1.current.length - 1];
24742479
pushHash(route.fullPath);
24752480
handleScroll(this$1.router, route, fromRoute, false);
24762481
onComplete && onComplete(route);
24772482
}, onAbort);
24782483
};
24792484

2480-
HashHistory.prototype.replace = function replace (location, onComplete, onAbort) {
2481-
var this$1 = this;
2485+
HashHistory.prototype.navigateLastLayer = function navigateLastLayer (location, push, onComplete, onAbort) {
2486+
var locations = this.current.slice(0, -1).map(function (r) { return r.fullPath; }).concat( [location]
2487+
);
2488+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2489+
};
24822490

2483-
var ref = this;
2484-
var fromRoute = ref.current;
2485-
this.transitionTo(location, function (route) {
2486-
replaceHash(route.fullPath);
2487-
handleScroll(this$1.router, route, fromRoute, false);
2488-
onComplete && onComplete(route);
2489-
}, onAbort);
2491+
HashHistory.prototype.navigateLayer = function navigateLayer (layer, location, push, onComplete, onAbort) {
2492+
var locations = this.current.slice(0, layer).map(function (r) { return r.fullPath; }).concat( [location],
2493+
this.current.slice(layer + 1).map(function (r) { return r.fullPath; })
2494+
);
2495+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2496+
};
2497+
2498+
HashHistory.prototype.navigateAddLayer = function navigateAddLayer (location, push, onComplete, onAbort) {
2499+
var locations = this.current.map(function (r) { return r.fullPath; }).concat( [location]
2500+
);
2501+
this.navigateAllLayers(locations, push, onComplete, onAbort);
2502+
};
2503+
2504+
HashHistory.prototype.navigateRemoveLayer = function navigateRemoveLayer (location, push, onComplete, onAbort) {
2505+
var locations = this.current.slice(0, -1).map(function (r) { return r.fullPath; });
2506+
this.navigateAllLayers(locations, push, onComplete, onAbort);
24902507
};
24912508

24922509
HashHistory.prototype.go = function go (n) {
24932510
window.history.go(n);
24942511
};
24952512

24962513
HashHistory.prototype.ensureURL = function ensureURL (push) {
2497-
var current = this.current.fullPath;
2498-
if (getHash() !== current) {
2499-
push ? pushHash(current) : replaceHash(current);
2514+
var route = this.current[this.current.length - 1];
2515+
if (getHash() !== route.fullPath) {
2516+
var path = cleanPath(this.base + route.fullPath);
2517+
pushState(path, this.current.map(function (r) { return r.fullPath; }), !push);
25002518
}
25012519
};
25022520

@@ -2742,7 +2760,7 @@ VueRouter.prototype.init = function init (app /* Vue component instance */) {
27422760
history.setupListeners();
27432761
};
27442762
history.transitionTo(
2745-
history.getCurrentLocation(),
2763+
[history.getCurrentLocation()],
27462764
setupHashListener,
27472765
setupHashListener
27482766
);

dist/vue-router.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)