-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix single page app routing with spa-github-pages
https://github.com/rafgraph/spa-github-pages/ So it turns out GitHub Pages doesn't actually do dynamic routing: if we try to access https://dgmstuart.github.io/bingo-frontend/numbers, then github looks for an html document matching that name, and doesn't find one so returns a 404. This was confusing for a while because it seemed like those pages were working on desktop and not mobile, but actually it seems like it was just caching which allowed them to be displayed? This approach is to define a specific 404 page which routes back to the index which then handles the route.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Single Page Apps for GitHub Pages</title> | ||
<script type="text/javascript"> | ||
// Single Page Apps for GitHub Pages | ||
// MIT License | ||
// https://github.com/rafgraph/spa-github-pages | ||
var pathSegmentsToKeep = 1; | ||
|
||
var l = window.location; | ||
l.replace( | ||
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + | ||
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' + | ||
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') + | ||
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + | ||
l.hash | ||
); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |