Skip to content

Root route match fails when trailingSlash: 'never' and base configuration enabled #16247

@aemaaeng

Description

@aemaaeng

Astro Info

Astro                    v5.16.5
Vite                     v6.4.1
Node                     v22.17.1
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node (v9.5.1)
Integrations             @astrojs/react (v4.4.2)

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

No response

Describe the Bug

When trailingSlash: 'never' is set alongside a base path in a Node.js standalone deployment, requests to the root path (e.g. /mybase) return a 404 instead of rendering the index page.

Root cause: getPattern() incorrectly set the root route regex to ^$ (matches empty string) when trailingSlash === 'never' and base !== '/'.

This does not reproduce in dev mode because Vite handles base path processing before Astro's route pattern matching is reached.

What's the expected result?

astro.config.mjs:
  - output: 'server'
  - adapter: node({ mode: 'standalone' })
  - base: '/mybase'
  - trailingSlash: 'never'
  • Request: GET /mybase
  • Expected: 200 (index page)
  • Actual: 404

Link to Minimal Reproducible Example

https://github.com/aemaaeng/astro-repro-base-trailing-slash

Participation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)pkg: nodeRelated to Node adapter (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions