From 6c19e6ebfff97ee5feec800bf80321a47d9db41b Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 30 Oct 2020 22:33:18 +0900 Subject: [PATCH] Fix #1294 use history.replaceState() to remove unnecessary comment_srl and page number from URL if new rewrite rules are in effect --- modules/board/tpl/js/board.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/board/tpl/js/board.js b/modules/board/tpl/js/board.js index c7877177c..d97bb5c7c 100644 --- a/modules/board/tpl/js/board.js +++ b/modules/board/tpl/js/board.js @@ -132,7 +132,24 @@ function doScrap(document_srl) jQuery.exec_json('member.procMemberScrapDocument', params); } + jQuery(function($){ + + /* remove comment_srl and unnecessary page number from short URL */ + var match = location.pathname.match(/\/([a-zA-Z0-9_]+)\/([0-9]+)\/(comment|page)\/([0-9]+)$/); + if (match && match[1] === window.current_mid) { + var newpath = location.pathname.replace(/\/(comment|page)\/([0-9]+)$/, ''); + if (location.hash && location.hash !== '#') { + newpath += location.hash; + } + if (history.replaceState) { + history.replaceState({ + rx_replaced: true, + prev: location.pathname, + }, '', newpath); + } + } + $(document.body).click(function(e){ var t = $(e.target), act, params = {};