diff --git a/client/js/main.js b/client/js/main.js index 1cca87d..d90add7 100644 --- a/client/js/main.js +++ b/client/js/main.js @@ -12,7 +12,7 @@ router.exit( (ctx, next) => { ctx.state.scrollX = window.scrollX; ctx.state.scrollY = window.scrollY; - ctx.save(); + router.replace(router.url, ctx.state); if (misc.confirmPageExit()) { next(); } diff --git a/client/js/router.js b/client/js/router.js index cfe405f..2226059 100644 --- a/client/js/router.js +++ b/client/js/router.js @@ -6,6 +6,8 @@ // - simplified method chains // - added ability to call .save() in .exit() without side effects // - page refresh recovers state from history +// - rename .save() to .replaceState() +// - offer .url const pathToRegexp = require('path-to-regexp'); const clickEvent = document.ontouchstart ? 'touchstart' : 'click'; @@ -47,7 +49,7 @@ class Context { history.pushState(this.state, this.title, this.canonicalPath); } - save() { + replaceState() { history.replaceState(this.state, this.title, this.canonicalPath); } }; @@ -149,10 +151,10 @@ class Router { var ctx = new Context(path, state); if (dispatch) { this.dispatch(ctx, () => { - ctx.save(); + ctx.replaceState(); }); } else { - ctx.save(); + ctx.replaceState(); } return ctx; } @@ -184,6 +186,10 @@ class Router { router.stop(); location.href = ctx.canonicalPath; } + + get url() { + return location.pathname + location.search + location.hash; + } }; const _onPopState = router => { diff --git a/client/js/views/endless_page_view.js b/client/js/views/endless_page_view.js index 142a6dc..8bf6a0d 100644 --- a/client/js/views/endless_page_view.js +++ b/client/js/views/endless_page_view.js @@ -65,7 +65,7 @@ class EndlessPageView { if (topPageNumber !== this.currentPage) { router.replace( ctx.getClientUrlForPage(topPageNumber), - {}, + ctx.state, false); this.currentPage = topPageNumber; } diff --git a/client/js/views/posts_header_view.js b/client/js/views/posts_header_view.js index 6824b87..da95a30 100644 --- a/client/js/views/posts_header_view.js +++ b/client/js/views/posts_header_view.js @@ -110,7 +110,7 @@ class PostsHeaderView { browsingSettings.listPosts[safety] = !browsingSettings.listPosts[safety]; settings.save(browsingSettings, true); - router.show(location.pathname + location.search + location.hash); + router.show(router.url); } _evtSearchFormSubmit(e) {