Refactor redirect URL code block into a function

This commit is contained in:
Helen Chong 2024-05-31 10:42:07 +08:00
parent a6ca591fee
commit 8eff9df6de
1 changed files with 8 additions and 4 deletions

View File

@ -2,7 +2,11 @@ const currentUrl = window.location.href;
const oldDomain = 'leilukin.neocities.org';
const newDomain = 'leilukin.com';
if (currentUrl.includes(oldDomain)) {
const newUrl = currentUrl.replace(oldDomain, newDomain);
location.replace(newUrl);
}
const redirectUrl = (oldStr, newStr) => {
if (currentUrl.includes(oldStr)) {
const newUrl = currentUrl.replace(oldStr, newStr);
location.replace(newUrl);
}
}
redirectUrl(oldDomain, newDomain);