Skip to content

Commit

Permalink
test: redirect to 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanGrenier committed Feb 28, 2025
1 parent cdcb92f commit ddcc5de
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
<script>
(function() {
if (sessionStorage.getItem('redirect')) {
const redirectPath = sessionStorage.getItem('redirect');
sessionStorage.removeItem('redirect');
window.history.replaceState(null, null, '/' + redirectPath);
}
})();
</script>
</html>
28 changes: 28 additions & 0 deletions public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Not Found</title>
<script>
// Single Page Apps for GitHub Pages
// https://github.com/rafgraph/spa-github-pages
const pathSegmentsToKeep = 0; // Site is published at the root of custom domain soen357.ngrenier.com

const l = window.location;
// Save the URL path (minus the repo part)
const redirectPath = l.pathname.split('/').slice(pathSegmentsToKeep + 1).join('/') +
(l.search ? l.search : '') + (l.hash ? l.hash : '');

// Redirect to the index.html with the path as a query parameter
sessionStorage.setItem('redirect', redirectPath);
l.replace(
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
l.pathname.split('/').slice(0, pathSegmentsToKeep + 1).join('/') + '/?/' +
redirectPath
);
</script>
</head>
<body>
Redirecting...
</body>
</html>
3 changes: 3 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { DefaultNotFoundRoute } from "./components/default-not-found-route";
import { RouterProvider, createRouter } from "@tanstack/react-router";
import { routeTree } from "./routeTree.gen";

// const hashHistory = createHashHistory();

const router = createRouter({
routeTree,
// history: hashHistory,
defaultNotFoundComponent: DefaultNotFoundRoute,
});

Expand Down

0 comments on commit ddcc5de

Please sign in to comment.