Last active
May 12, 2023 20:13
-
-
Save luislobo14rap/1082bda3f3009bf1698058ae50477459 to your computer and use it in GitHub Desktop.
change-url-without-reload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// change-url-without-reload.js v1 | |
function changeURLWithoutReload(newUrl){ | |
let url = getURL(); | |
return window.history.pushState(undefined, undefined, url + '/' + newUrl.replace(/^\//, '')); | |
}; | |
// getURL.js v1 | |
function getURL(url = window.location.href){ | |
return url.split(/[?#&]/)[0].replace(/\/+$/, ''); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let url = window.location.href | |
if( (/\d{5,}/).test(url) ) { | |
window.history.pushState({}, '', url.replace(/\d{5,}/, 'newlink') ); | |
} else { | |
window.history.pushState({}, '', url + 'pin/newlink/' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment