-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When refreshing on anything but the root page (when in GH pages) redi…
…rects to GH 404 - fix that
- Loading branch information
Showing
2 changed files
with
25 additions
and
1 deletion.
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,24 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// because GH pages doesn't support SPA routing, we need to redirect all 404s to the root | ||
const distPath = path.join(__dirname, '../dist/team-app'); | ||
const indexPath = path.join(distPath, 'index.html'); | ||
const notFoundPath = path.join(distPath, '404.html'); | ||
|
||
fs.copyFileSync(indexPath, notFoundPath); | ||
|
||
const redirectScript = ` | ||
<script> | ||
if (location.pathname !== "/") { | ||
location.replace('/#' + location.pathname); | ||
} | ||
</script> | ||
</body>`; | ||
|
||
let htmlContent = fs.readFileSync(notFoundPath, 'utf8'); | ||
|
||
// Replace the closing body tag with the script followed by the closing body tag | ||
htmlContent = htmlContent.replace('</body>', redirectScript); | ||
|
||
fs.writeFileSync(notFoundPath, htmlContent); |