From 0ca3ee9c073592ec931a8f348933459b96916966 Mon Sep 17 00:00:00 2001 From: s2 Date: Fri, 3 Jan 2020 21:51:13 +0100 Subject: [PATCH] make query strings work with pagejs --- js/index.js | 2 +- node_modules/page/page.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/js/index.js b/js/index.js index cc1e3e1..11e0f00 100644 --- a/js/index.js +++ b/js/index.js @@ -81,7 +81,7 @@ if (urlQueryString.has('lang')) { urlQueryString.delete('lang'); var newUrl = [location.protocol, '//', location.host, location.pathname].join('') + - urlQueryString.toString() + + (urlQueryString.toString() !== '' ? '?' + urlQueryString.toString() : '') + window.location.hash; window.location = newUrl; return; diff --git a/node_modules/page/page.js b/node_modules/page/page.js index 82858a5..b35bac6 100644 --- a/node_modules/page/page.js +++ b/node_modules/page/page.js @@ -1126,8 +1126,11 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1; Context.prototype.save = function() { var page = this.page; if (hasHistory) { - page._window.history.replaceState(this.state, this.title, - page._hashbang && this.path !== '/' ? '#!' + this.path : this.canonicalPath); + var pathWithoutQuerystring = this.path.replace('?' + this.querystring, ''); + pathWithoutQuerystring = pathWithoutQuerystring === '' ? '/' : pathWithoutQuerystring; + + page._window.history.replaceState(this.state, this.title, + page._hashbang && pathWithoutQuerystring !== '/' || this.querystring !== '' ? page._window.location.pathname + '#!' + this.path : this.canonicalPath); } }; @@ -1189,7 +1192,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1; m = this.regexp.exec(decodeURIComponent(pathname)); if (!m) return false; - + delete params[0] for (var i = 1, len = m.length; i < len; ++i) {