Skip to content

Astro.url.pathname returns wrong value when build.format=preserve, when building #13615

@lgh06

Description

@lgh06

Astro Info

Astro                    v5.6.1
Node                     v22.14.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/react

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

astro.config.mjs:

import { defineConfig } from 'astro/config';
import react from '@astrojs/react';

export default defineConfig({
  integrations: [react()],
  build: {
    format: 'preserve',
  },
  i18n: {
    locales: ["zh", "en"],
    defaultLocale: "zh",
  }
});

This is a console.log(Astro.url) on src/pages/user-agent.astro, when npm run build:

src/pages/user-agent.astro
10:26:35   └─ /user-agent.html

URL {
  href: 'http://localhost:4321/user-agent/',
  origin: 'http://localhost:4321',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'localhost:4321',
  hostname: 'localhost',
  port: '4321',
  pathname: '/user-agent/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Obviously, the right pathname should be /user-agent.html, not /user-agent/

What's the expected result?

the right pathname should be /user-agent.html, not /user-agent/

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-pjzyezut?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)feat: routingRelated to Astro routing (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions