Skip to content

Angular SSR: Express routes are only prefixed in development with baseHref setΒ #31896

@brandonroberts

Description

@brandonroberts

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When setting the baseHref, all dev server requests are required to be prefixed, even if I have routes in my server.ts that do not need the baseHref, such as health check endpoints.

Then when building the application the endpoint works without the baseHref, causing a mismatch of behavior between dev and build.

Minimal Reproduction

https://github.com/brandonroberts/angular-ssr-base-href

  1. Clone the repo
  2. Run npm install
  3. Run npm start
  4. Visit http://localhost:4200/ping
  5. Note the error message that the URL should be http://localhost:4200/custom/ping
  6. Stop the dev server
  7. Run npm run build
  8. Run npm run serve:ssr:angular-ssr-base-href
  9. Visit http://localhost:4000/ping
  10. Note the route displays correctly

Exception or Error


Your Environment

Angular: 20.3.12
... common, compiler, compiler-cli, core, forms
... platform-browser, platform-server, router

Package                      Version
------------------------------------
@angular-devkit/architect    0.2003.10
@angular-devkit/core         20.3.10
@angular-devkit/schematics   20.3.10
@angular/build               20.3.10
@angular/cli                 20.3.10
@angular/ssr                 20.3.10
@schematics/angular          20.3.10
rxjs                         7.8.2
typescript                   5.9.3
zone.js                      0.15.1

Anything else relevant?

Tested with Angular v21 also

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions