SPACE.LA
◀ music select
personal / experiment / archived

gh-pages-spa

A demo of serving an AngularJS single-page app from GitHub Pages, using a 404.html fallback and symlinked routes.

BPM
166
GRADE
C
LEVEL
5
RELEASES
0
YEARS
2016–2016

Routing On A Dumb Host

GitHub Pages serves static files. Ask it for /about and it looks for a file called about, doesn't find one, and gives you a 404. That breaks single-page apps with client-side routing, which in May 2016 was everything I was building.

So I spent a day testing the workaround. Serve the AngularJS app and use 404.html as the catch-all: whatever path the browser asks for falls back to 404.html, and the router picks up the URL and renders the right view. I also symlinked common routes so they resolved directly.

Free hosting, no server, and deep links still work. A week earlier I'd rehosted the 20X20 archive on the same platform. The trick wasn't mine; I just wanted to make sure it worked before using it on a real project.