diff --git a/src/plugins/url/UrlPlugin.js b/src/plugins/url/UrlPlugin.js index f965674ba..4f1fd36cb 100644 --- a/src/plugins/url/UrlPlugin.js +++ b/src/plugins/url/UrlPlugin.js @@ -151,7 +151,9 @@ export class UrlPlugin { } if (this.urlMode == 'hash') { - window.location.replace('#' + concatenatedPath); + // Use location.hash instead of location.replace('#...') to preserve + // the current pathname in SPA contexts. + window.location.hash = concatenatedPath; } this.oldLocationHash = urlStrPath; } diff --git a/src/plugins/url/plugin.url.js b/src/plugins/url/plugin.url.js index 6f9368ded..b26fd2d40 100644 --- a/src/plugins/url/plugin.url.js +++ b/src/plugins/url/plugin.url.js @@ -206,7 +206,10 @@ BookReader.prototype.urlUpdateFragment = function() { } else if (this.textFragmentPage && extractedPage != this.textFragmentPage) { textFragment = ''; } - window.location.replace('#' + newFragment + newQueryStringSearch + textFragment); + // Use location.hash instead of location.replace('#...') to preserve + // the current pathname. location.replace('#foo') is a relative URL + // that can wipe the path in SPA contexts. + window.location.hash = newFragment + newQueryStringSearch + textFragment; this.oldLocationHash = newFragment + newQueryStringSearch + textFragment; } };