]> git.ardis.lu - ardislu.dev/commitdiff
Use location.replace for 404 redirect
authorArdis Lu <ardisglu@gmail.com>
Sun, 27 Feb 2022 05:16:10 +0000 (21:16 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sun, 27 Feb 2022 05:16:10 +0000 (21:16 -0800)
This prevents adding an extra page in history, so users can press back once to go to the original page as expected.

script.js

index 0bb9f929b5fa227141ecae5fc8fc7bee7bd3e0c0..a536a2ca931415e52e7549d950034696ab5a275d 100644 (file)
--- 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`);
   }
 }
 
This page took 0.036019 seconds and 4 git commands to generate.