Skip to content

Commit 234ba58

Browse files
authored
Merge pull request #442 from raifdmueller/fix/router-trailing-slash
fix: SPA router ignores trailing slash, breaking direct URL visits (#441)
2 parents 10d889e + f10c732 commit 234ba58

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

website/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/src/utils/router.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,15 @@ export function initRouter() {
136136
* Handle route change
137137
*/
138138
function handleRoute() {
139-
const path = getCurrentRoute()
139+
let path = getCurrentRoute()
140+
141+
// Normalize trailing slash: GitHub Pages 301-redirects /workflow to /workflow/
142+
// when workflow/index.html is served as a directory index. Without this,
143+
// routes.get('/workflow/') misses the '/workflow' key and falls through to
144+
// the home handler.
145+
if (path.length > 1 && path.endsWith('/')) {
146+
path = path.slice(0, -1)
147+
}
140148

141149
// Check for anchor route (/anchor/:id)
142150
if (path.startsWith('/anchor/')) {

website/tests/e2e/website.spec.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,27 @@ test.describe('Routing - Documentation Pages', () => {
277277
await expect(anchorsLink).toHaveClass(/font-semibold/)
278278
})
279279

280-
test.skip('should handle direct URL to About page', async ({ page }) => {
281-
// Skip: direct URL routing requires 404.html fallback (only works on GitHub Pages)
282-
await page.goto('/about')
280+
test('should handle direct URL to About page', async ({ page }) => {
281+
await page.goto('/Semantic-Anchors/about')
283282

284283
// Wait for AsciiDoc content to load and check h1 in content area (not header)
285284
await page.waitForSelector('#doc-content h1', { timeout: 10000 })
286285
await expect(page.locator('#doc-content h1')).toContainText(/About|What are/)
287286
})
288287

288+
test('should render doc page when visited via trailing-slash URL', async ({ page }) => {
289+
// GitHub Pages 301-redirects /workflow → /workflow/ when workflow/index.html
290+
// is served as a directory index. The SPA must handle the trailing-slash
291+
// form or it falls through to the home handler.
292+
await page.goto('/Semantic-Anchors/workflow/')
293+
294+
await page.waitForSelector('#doc-content h1', { timeout: 10000 })
295+
await expect(page.locator('#doc-content h1')).toContainText(/Workflow/i)
296+
297+
// Card grid (home-only content) must not be rendered on top
298+
await expect(page.locator('.anchor-card')).toHaveCount(0)
299+
})
300+
289301
test('should handle browser back button', async ({ page }) => {
290302
// Navigate to About via More dropdown
291303
await page.locator('#more-menu-toggle').click()

0 commit comments

Comments
 (0)