Skip to content

Add SPA redirect handling for GitHub Pages#1

Open
bradmanners wants to merge 1 commit into
mainfrom
codex/create-404-redirect-page-for-spa
Open

Add SPA redirect handling for GitHub Pages#1
bradmanners wants to merge 1 commit into
mainfrom
codex/create-404-redirect-page-for-spa

Conversation

@bradmanners

Copy link
Copy Markdown
Owner

Summary

  • add a spa-github-pages compatible redirect page at public/404.html so unknown routes send visitors to the SPA entrypoint
  • inject a small history-rewrite helper in index.html to restore the original path after the redirect
  • include the generated dist assets (including 404.html) so GitHub Pages serves the new bootstrap

Testing

  • pnpm build

https://chatgpt.com/codex/tasks/task_e_68cdc99ca37c8322831e09757b73443e

Copilot AI review requested due to automatic review settings September 19, 2025 21:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements SPA (Single Page Application) redirect handling for GitHub Pages deployment. It adds client-side routing support to handle unknown routes by redirecting them through a custom 404 page back to the main application.

  • Adds a custom 404.html page that captures unknown routes and redirects to the main app with encoded path parameters
  • Injects JavaScript into index.html to decode and restore the original URL path after redirect
  • Enables proper SPA routing behavior on GitHub Pages static hosting

Reviewed Changes

Copilot reviewed 2 out of 8 changed files in this pull request and generated 2 comments.

File Description
public/404.html Custom 404 page that encodes route information and redirects to main app
index.html Adds client-side script to decode and restore original URLs from redirect parameters

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread index.html
.map(function (s) {
return s.replace(/~and~/g, "&");
})
.join("?");

Copilot AI Sep 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL decoding logic assumes the search string starts with '/' but joins with '?' which creates malformed URLs. This should join with '&' to maintain proper query parameter format.

Suggested change
.join("?");
.join("&");

Copilot uses AI. Check for mistakes.
Comment thread index.html
var params = new URLSearchParams(l.search);
var path = params.get("p");
if (path) {
var query = params.get("q");

Copilot AI Sep 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query parameter should be decoded using the same ~and~ replacement logic as used in the 404.html encoding to ensure consistency.

Suggested change
var query = params.get("q");
var query = params.get("q");
if (query) query = query.replace(/~and~/g, "&");

Copilot uses AI. Check for mistakes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment thread index.html
Comment on lines +28 to +32
var params = new URLSearchParams(l.search);
var path = params.get("p");
if (path) {
var query = params.get("q");
var target = "/" + path + (query ? "?" + query : "") + l.hash;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Restore decoded query params after SPA redirect

The history-rewrite helper reconstructs the path from ?p= and ?q= parameters but it never reverses the ~and~ encoding that the new 404 redirect applies. Navigating directly to a route with multiple query parameters (e.g. /search?term=a&sort=asc) produces /search?term=a~and~sort=asc after the redirect, so the router receives an incorrect query string. Decode the path and query values with replace(/~and~/g, '&') before calling replaceState so the original URL is restored.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants