Skip to content

Commit 54141b8

Browse files
committed
Update fix-trailing-slash.js
1 parent d7fa943 commit 54141b8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

static/js/fix-trailing-slash.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
if (window && window.location && window.location.pathname.endsWith('/') && window.location.pathname !== '/') {
2-
window.history.replaceState('', '', window.location.pathname.substr(0, window.location.pathname.length - 1))
2+
// Preserve query parameters and hash when removing trailing slash
3+
const newPath = window.location.pathname.substr(0, window.location.pathname.length - 1);
4+
const search = window.location.search || '';
5+
const hash = window.location.hash || '';
6+
window.history.replaceState('', '', newPath + search + hash);
37
}

0 commit comments

Comments
 (0)