Skip to content

withHashLocation is not compatible with SSR (throws TypeError: Invalid URL when parsing "#/") #68322

@eblocha

Description

@eblocha

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

Yes

Description

When the withHashLocation feature is used under SSR, the build will hang after throwing an exception.

Please provide a link to a minimal reproduction of the bug

https://github.com/eblocha/ng-ssr-hash-routing

Please provide the exception or error you saw

ERROR TypeError: Invalid URL
    at new URL (node:internal/url:819:25)
    at HD (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:40:31721)
    at e.replaceState (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:40:32574)
    at e.replaceState (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:31:54829)
    at e.replaceState (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:31:52733)
    at e.setBrowserUrl (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:40:95885)
    at e.handleRouterEvent (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:40:95478)
    at Object.next (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:40:98624)
    at uf.next (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:4:3112)
    at ao._next (file:///Users/elliot.blocha/projects/scratch/ssr-test/.angular/prerender-root/fa99184b-c1cb-46ed-80af-134e4ceff1a7/main.server.mjs:4:2795) {
  code: 'ERR_INVALID_URL',
  input: '#/'

Please provide the environment you discovered this bug in (run ng version)

Angular CLI       : 21.2.7
Angular           : 21.2.9
Node.js           : 24.15.0
Package Manager   : npm 11.12.1
Operating System  : darwin arm64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.2.7            │ ^21.2.7           │
│ @angular/cli              │ 21.2.7            │ ^21.2.7           │
│ @angular/common           │ 21.2.9            │ ^21.2.9           │
│ @angular/compiler         │ 21.2.9            │ ^21.2.9           │
│ @angular/compiler-cli     │ 21.2.9            │ ^21.2.9           │
│ @angular/core             │ 21.2.9            │ ^21.2.9           │
│ @angular/forms            │ 21.2.9            │ ^21.2.9           │
│ @angular/platform-browser │ 21.2.9            │ ^21.2.9           │
│ @angular/platform-server  │ 21.2.9            │ ^21.2.9           │
│ @angular/router           │ 21.2.9            │ ^21.2.9           │
│ @angular/ssr              │ 21.2.7            │ ^21.2.7           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
│ vitest                    │ 4.1.0             │ ^4.0.8            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else?

No response

Metadata

Metadata

Assignees

Labels

area: serverIssues related to server-side renderinggemini-triagedLabel noting that an issue has been triaged by geminiregressionIndicates than the issue relates to something that worked in a previous version

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions