Skip to content

Commit 615ee61

Browse files
committed
Fix 404 for direct link access
GitHub pages handles requests differently to the current setup for client-siderouting, which is causing 404 errors if you refresh a page or attempt to visit a URL provided by someone. The site is generated with links that _don't_ have a trailing slash to denote a folder, e.g. `href="/ways-of-working"` when the actual HTML is stored in `/ways-of-working/index.html`. The client-side routing is configured in the same way, so within the site all links work. The build also succeeds because there are no invalid links according to the client-side routing rules. That in itself is not a problem, however GitHub pages doesn't resolve a non-trailing slash path to the `index.html` within the folder. Instead it's looking for content in `/ways-of-working.html`, which doesn't exist. As a result no links that are generated or valid within the Docusaurus Single Page App will resolve when accessed directly in GitHub Pages. This change configures Docusaurus to use trailing slashes for folders, which will change both the way it generates output folders/files _and_ how client side routing works. This _should_ make client and server routing consistent and fix the problem. This hasn't been tested because we don't have a staging environment so the easiest way to validate the fix is to ship it to production and revert it if we don't get the results we want. 1. Visit the playbook.hackey.gov.uk 2. Navigate to Ways of Working 3. Hard refresh or open the same link in a a new window. 4. Validate that the page isn't a 404
1 parent 4f42b3a commit 615ee61

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

docusaurus.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const config = {
2222
// If you aren't using GitHub pages, you don't need these.
2323
organizationName: 'LBHackney-IT', // Usually your GitHub org/user name.
2424
projectName: 'lbhackney-it.github.io', // Usually your repo name.
25+
26+
// CAUTION! This alters how client routing behaves but NOT the hosting
27+
// provider. See https://github.com/slorber/trailing-slash-guide
28+
// GitHub pages returns 404s when refreshing a page when trailingSlash: false
2529
trailingSlash: false,
2630

2731
onBrokenLinks: 'throw',

0 commit comments

Comments
 (0)