Skip to content

How to support routes with and without locale prefix in Fresh 2 without duplicating files? #3502

@marvinhagemeister

Description

@marvinhagemeister

Discussed in #3501

Originally posted by s00d September 27, 2025
Hi!

I’m trying to implement i18n in Fresh 2.
The goal is to support URLs both with locale prefix and without it, e.g.:

  • /aaa
  • /de/aaa
  • /ru/blog/some-post

I want both variants to resolve to the same route file (e.g. routes/aaa.tsx or routes/blog/[slug].tsx) without duplicating files under each locale folder.

I tried using middleware:

  • It correctly detects the locale from the first URL segment.
  • But ctx.next() still resolves against the original URL (/de/aaa) → Fresh looks for routes/de/aaa.tsx (which doesn’t exist) → 404.
  • Fresh doesn’t allow passing a modified Request to ctx.next(), so I cannot “rewrite” the path like in Next.js.

Questions:

  • Is there an official / recommended way in Fresh 2 to handle this use case?
  • Does the team plan to support some form of URL rewriting in middleware (so /de/aaa can transparently resolve to routes/aaa.tsx)?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions