Repository navigation
fix(pages): redirect /en, /index and the home slug to the home page - #120
Conversation
`+onBeforeRoute` needs a redirect target as a path: `modifyUrl` rebuilds the origin itself, and carrying the query across depends on that. The locale prefix rule lived only inside `localeUrl`, which concatenates an origin, so a consumer wanting the path alone had to restate the rule — which the repo convention on `lib/urls.ts` forbids. `localePath` holds the rule and `localeUrl` prefixes an origin to it. Behaviour is unchanged, and the existing `localeUrl` specs still cover both halves. `isIndexPath` names the router's own `/index` spelling so a caller can recognize one without spelling it a third time. It matches a trailing slash too: `/index/` reaches `pages/[slug]/+route.ts` as slug `index` just as `/index` does. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
`/en` 301'd to `/index`, which returns 200 and renders the home page —
whose own canonical is `/`. The site served the home page at two URLs and
pointed crawlers at the second one through a permanent redirect. `/index`
was also reachable directly, and once per locale as `/<locale>/index`.
`/index` is the spelling `+onBeforeRoute` invents so the router can match
the home page, and `lib/urls.ts` already owns the inverse. The redirect
now runs `pathWithoutLocale` through `normalizeContentPath`, and a
*requested* `/index` 301s to the home URL of its locale. Only the
requested path can tell the two apart: `localeFromPath` gives a bare
locale root the same `/index`, so the invented spelling can never be
mistaken for one a browser asked for. `urlLogical` keeps `/index`, since
`pages/[slug]/+route.ts` returns false for a bare `/`.
Confirmed against `pnpm dev`, reading `%{redirect_url}` and the followed
chain:
/en 301 -> / (was /index)
/index 301 -> / (was 200)
/en/index 301 -> / (was /index)
/fr/index 301 -> /fr (was 200)
/pt-BR/index 301 -> /pt-BR (was 200)
/en/about?x=1 301 -> /about?x=1 unchanged, query preserved
/status/page 404 unchanged, not a locale prefix
/about/index 404 unchanged, /index only at the root
A trailing slash is Vike's, not ours: `normalizeUrlPathname` runs at
`renderPageServer.js:414`, before routing, so `/en/` 301s to `/en` and
`/en/about/` to `/en/about` before this hook sees either. Both then take
the redirect above, so `/en/` ends on `/` and `/en/about/` on `/about` in
two hops. `/index/` reaches `/` the same way. The ticket predicted one
hop for `/en/` because it executed the hook in isolation.
`pages/onBeforeRoute.test.ts` asserted only that `/en/about` throws, which
is why this survived: reverting the hook leaves the three new target
specs failing and the ten old ones green. The smoke spec asserted only
that the target no longer contains `/en`, which `/index` satisfied, so it
passed before and after the fix. It now reads the target's pathname.
Local rendering cannot reach the CMS from this sandbox, so `/` and `/fr`
answer 500 on the translations read. They route: a 500 from the data hook
is not the 404 a routing regression would give. The preview smoke run
covers the 200.
Refs #114
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
Three review findings converge on one edit. `+onBeforeRoute` re-derived the
locale-free path by slicing `locale.length + 1` off the raw pathname,
restating a prefix shape `localeFromPath`'s regex already matched — the
thing the `lib/urls.ts` convention exists to prevent. `localeFromPath`
now reports `requestedIndex`, computed from the match it already has, so
the consumer asks instead of re-parsing.
`isIndexPath` is gone with it. It had been a second definition of the
`/index` spelling, and it disagreed with the one in
`normalizeContentPath`: `normalizeContentPath('/index/')` stripped the
slash and returned `/index`, so `/en/index/` would have 301'd back onto
the spelling this branch redirects away from. One private `INDEX_PATH`
now answers for both, and `/index/` normalizes to `/`.
Also drop a duplicated `routeOf('/')` assertion the bare-root spec above
already makes, and a comment sentence narrating the `modifyUrl` call
beside it.
Re-verified on `pnpm dev`: every target in the previous commit is
unchanged, `/en/index/` now resolves to `/`, and `/indexes` still routes
as a slug rather than redirecting.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
The spec claimed `/about/` and `/about` both render, so the 301 must not land on the duplicate. Vike's `normalizeUrlPathname` 301s the slash before routing (`renderPageServer.js:414`), so no server request reaches this hook carrying one. The spec still pins the hook's own answer, which is what it should say. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
`docs/cloudflare-previews-ci.md` stated `/en` redirects to `/index`, under a heading promising each fact matches the deployed Worker. The URL-spelling convention in `AGENTS.md` named `localeUrl` and said nothing about the `/index` spelling a consumer must not point at. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
Deploying wemeditate-design with
|
| Latest commit: |
3f1d656
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://63a85b89.wm-design.pages.dev |
| Branch Preview URL: | https://claude-fix-114-index-redirec.wm-design.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | 3f1d656 | Commit Preview URL Branch Preview URL |
Sep 18 2026, 11:21 PM |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the size of #114. localePath is the only new export, and two callers need it because modifyUrl takes a pathname. On the branch preview /en, /en/index, /index and /fr/index each land in one hop, and / now canonicalises to itself. The unmet criterion — /en/ in one hop — is disclosed, and its argument holds. No contract surface is touched.
Findings — no blockers.
considerthe "one hop" spec name outruns what the server does — pages/onBeforeRoute.test.ts:101considerthe other home-page twin,/<homeSlug>, stays open — pages/+onBeforeRoute.ts:18considerthe new guide bullet restates the one above it — AGENTS.md:183
Checked. Read whole: lib/urls.ts, the hook, both specs. Every consumer of the changed helpers: lib/head.tsx:183, lib/hreflang.ts:93, layouts/LayoutChrome.tsx:114, pages/+onCreatePageContext.server.ts:30. Probed 11 preview paths. /fr 404s because the home document advertises only en. #115 already covers Link and EmbedButton restating the prefix rule.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The spec name read as #114's unmet acceptance criterion. Vike 301s a trailing slash before routing, so /en/ reaches its target in two hops even though the hook answers in one. A later reader could have cited a green spec as proof the criterion was met. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YTnExwDbTdUkh9ZHfUjtDH
The bullet above already states that normalizeContentPath undoes the /index spelling. What it does not state is that a redirect target goes through it too, and that a requested /index now 301s. The guide says it stays short on purpose. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YTnExwDbTdUkh9ZHfUjtDH
|
Addressed the adversarial review on 26ef933. Lean gate green: lint,
Re-confirmed on the branch preview: 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Both sides edited the `lib/urls.ts` bullet in AGENTS.md and the import line in `lib/urls.test.ts`. Kept both: this branch's `requestedIndex`/`localePath` rules alongside main's `isSafeHttpUrl`/`isSafeNavigationUrl` scheme rule. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01J1L7KdeDU1A7AeVeyexhL8
|
Merged
Lean gate green on the merge: lint 0 errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`wm-web-config.homePage` is served at `/`. `[slug]/+route.ts` also matched that document's own slug, so an editor who filled the slug in would have put one document at two 200 URLs — #114's shape at a second URL. The check reads the config rather than trusting today's empty slug to hold, and 302s rather than 301s: `/index` is a routing spelling and permanent, while a `homePage` slug is editorial and a cached 301 would outlive a change of home document. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Te95FaUSUTGcDQgX5dcw7C
|
Addressed the review on 041fddc. Lean gate green: lint,
It 302s where ⚠ The branch conflicts with 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#118 split `localeUrl` into `localePath` + `localeUrl` and added `isSitePath`. This branch had made the same split, for its own redirect targets. Three files conflicted; both behaviours are kept. - `lib/urls.ts` — the two splits are identical code, so main's version of that tail stands and `isSitePath` survives. This branch's `INDEX_PATH` and `requestedIndex` sit above it, untouched by either side. - `lib/urls.test.ts` — the import list only. - `AGENTS.md` — main's rewritten URL-spelling bullet, plus this branch's `requestedIndex` clause and its `/index is routing-internal` bullet. Lean gate green after the merge: lint 0 errors, tsc clean, 74 files / 710 tests. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UEYDbxwjGimsypgzrvzJnQ
|
Merged
Lean gate green after the merge: lint 0 errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
/en301'd to/index, a 200 duplicate of the home page whose own canonical is/. It now lands on/./indexand/<locale>/indexwere reachable directly and served the home page again. Both now 301 to that locale's home URL./<homeSlug>now 302s to the locale's home URL.Changes
lib/urls.ts—localeFromPathreportsrequestedIndex, so a consumer can tell a requested/indexfrom the spelling the hook invents for a bare root.localePathholds the locale-prefix rule andlocaleUrlprefixes an origin to it. One privateINDEX_PATHnow answers for bothrequestedIndexandnormalizeContentPath.pages/+onBeforeRoute.ts— the de-localizing 301 runs its target throughnormalizeContentPath, and a requested/index301s tolocalePath(locale, '/').pages/[slug]/+data.ts— a request whose slug equalswm-web-config.homePage.slug302s tolocalePath(locale, '/'). The routing hook cannot do this: the answer comes from the config, and+onBeforeRoutereads no CMS.pages/[slug]/data.test.ts,pages/onBeforeRoute.test.ts—redirectOfcatches the abort and reads_urlRedirect, so a spec can assert the target.server/sitemap-routes.ts— a comment only. It claimed/<homeSlug>was a second 200; it is now a redirect, and the sitemap still omits it.AGENTS.md— one bullet records that/indexis routing-internal and that a redirect target goes throughnormalizeContentPathtoo.Preview
https://claude-fix-114-index-redirect-wemeditate-web.contact-c66.workers.dev
Confirmed on that preview, reading
%{http_code}and%{redirect_url}:/en/index//index//en/index/index//fr/index/fr/pt-BR/index/pt-BR/en/about/about/about, unchanged///status/page,/about/index,/indexes/fr404s on the preview. That is not this PR: the home document advertises onlyen, so no French home page exists to serve.The
/<homeSlug>redirect has no preview row: the live config's home document has an empty slug, so there is no URL to request.pages/[slug]/data.test.tsstands in for it, and reverting the check fails exactly its three target specs.Test results
.claude/skills/pr-prep/check.sh— lint (0 errors),tsc --noEmit, 73 files / 697 testslib/urls.test.ts,pages/onBeforeRoute.test.ts,pages/[slug]/data.test.ts)Notes for reviewer
GET /en/reach its destination in one hop. It takes two: Vike'snormalizeUrlPathname301s the trailing slash to/enbefore routing (renderPageServer.js:414), and/enthen 301s to/. Same for/en/about/→/en/about→/about. Both end on the right URL. Removing the first hop means changing Vike'strailingSlashconfig or adding Hono middleware, which is a separate decision. The ticket predicted one hop because it executed the hook in isolation, where that normalization does not run.normalizeContentPath('/index/')used to return/index— it stripped the slash before its/indexcheck, so a canonical on/index/pointed at a URL this PR turns into a 301. It now returns/. That fix is inside this PR's own blast radius rather than a widening./<homeSlug>302s, where/index301s./indexis a routing spelling and permanent. A home slug is editor data: movehomePageto another document and a cached 301 would leave the old slug unreachable for everyone who visited it first. Say so on the thread if you want 301 anyway.components/atoms/Link/Link.tsxrestating the locale-prefix rule and not normalizing itshrefare already filed as fix(links): Link and EmbedButton each restate the locale-prefix rule #115 and fix(urls): Link does not normalize its href, so a trailing slash spells a page twice #119. Not touched here.server/path now appears in the diff, matchingsecurityReview.triggerPattern, but the change there is a comment.Detail
Why the redirect lives in
+data.tsand not the routing hook.+onBeforeRouteruns before any CMS read and would have to fetchwm-web-configon every request to know the home slug.+data.tsalready awaits that config for the page it is about to render, so the check costs no extra read and cannot disagree with the value the render uses.Why
requestedIndexrather than a check in the hook.localeFromPathreturns/indexaspathWithoutLocalefor both/frand/fr/index, so the two are indistinguishable downstream. The first draft recovered the difference in the hook by slicinglocale.length + 1off the raw pathname — which restates the prefix shapelocaleFromPath's regex already matched, against this repo'slib/urls.tsconvention. Computing the answer from the match that already exists removes the duplicate knowledge.Why the smoke spec had to change. Its assertion was
not.toMatch(/\/en(\/|$)/), which/indexsatisfies — it passed before and after the fix. It now readsnew URL(res.location!).pathname.How "reverting proves the spec" was checked. With
pages/+onBeforeRoute.tsrestored fromorigin/mainand the new specs in place, exactly the three target specs fail and the ten pre-existing ones stay green. The same check onpages/[slug]/+data.ts: three of its five specs fail, two pass.Why one spec lost the words "in one hop". It asserts
/en,/en/and/en/index, and/en/reaches/in two. The name read as the ticket's unmet criterion, so a green spec could have been cited as proof it was met.Rejected: exporting
isIndexPathfor the hook to call. It was a second definition of the/indexspelling and disagreed withnormalizeContentPath's. A module-private regex, consumed throughrequestedIndexandnormalizeContentPath, leaves one.Tool limitation: the sandbox's proxy blocks the CMS from the workerd runtime (
Error: Network connection lost), so no page renders 200 locally. Every assertion above was taken from the deployed branch preview or a real dev server.Closes #114
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01Te95FaUSUTGcDQgX5dcw7C