From: Ardis Lu Date: Sun, 27 Feb 2022 05:16:10 +0000 (-0800) Subject: Use location.replace for 404 redirect X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=c45fe27bacf3463440b80a84f07498d05bc17c3b;p=ardislu.dev Use location.replace for 404 redirect This prevents adding an extra page in history, so users can press back once to go to the original page as expected. --- diff --git a/script.js b/script.js index 0bb9f92..a536a2c 100644 --- a/script.js +++ b/script.js @@ -137,7 +137,8 @@ async function showPage(path) { else { // MUST redirect to a page where the web server serves an actual 404 error (i.e. not just // index.html again) otherwise this triggers an infinite loop - window.location.href = `${window.location.protocol}//${window.location.host}/errors/NotFound`; + document.title = '404: Not Found'; + window.location.replace(`${window.location.protocol}//${window.location.host}/errors/NotFound`); } }