Repository: angular
Issue: Router throws unhandled exception: SecurityError: Failed to execute 'replaceState' on 'History'
Labels: area: router,P4

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

router

### Is this a regression?

No

### Description

Hello,
i noticed an issue with angular router. If you enter a broken URL, such as 'www.example.com///test', then this exception will be thrown:

<img width="936" alt="image" src="https://user-images.githubusercontent.com/73908836/228142608-4f36e801-1d5e-4148-9358-d774041109cd.png">

I prepared a repository with an example (Don't let the name of the repo confuse you. I've used it before for a different problem). Inside routing module is a simple wildcard route which should route every wrong/broken url to 'TestComponent'. But when entering 'http://localhost:4200///test' the page crashes and the exception above is thrown. Please note that if you use two or four slashes this exception is not thrown. There must be exactly three slashes. 

### Please provide a link to a minimal reproduction of the bug

https://github.com/Floscho2402/angular-working-anchor-links

### Please provide the exception or error you saw

```true
ERROR Error: Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'http://test/' cannot be created in a document with origin 'http://localhost:4200' and URL 'http://localhost:4200///test'.
Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'http://test/' cannot be created in a document with origin 'http://localhost:4200' and URL 'http://localhost:4200///test'.
    at BrowserPlatformLocation.replaceState (common.mjs:171:27)
    at PathLocationStrategy.replaceState (common.mjs:406:32)
    at Location.replaceState (common.mjs:676:32)
    at Router.setBrowserUrl (router.mjs:5630:27)
    at Object.next (router.mjs:4747:32)
    at source.subscribe.isUnsub (tap.js:17:81)
    at OperatorSubscriber._next (OperatorSubscriber.js:13:21)
    at OperatorSubscriber.next (Subscriber.js:31:18)
    at map.js:7:24
    at OperatorSubscriber._next (OperatorSubscriber.js:13:21)
    at resolvePromise (zone.js:1214:31)
    at resolvePromise (zone.js:1168:17)
    at zone.js:1281:17
    at _ZoneDelegate.invokeTask (zone.js:409:31)
    at core.mjs:25299:55
    at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:25299:36)
    at _ZoneDelegate.invokeTask (zone.js:408:60)
    at Object.onInvokeTask (core.mjs:25607:33)
    at _ZoneDelegate.invokeTask (zone.js:408:60)
    at Zone.runTask (zone.js:178:47)
handleError @ core.mjs:9095
next @ core.mjs:26304
next @ Subscriber.js:91
_next @ Subscriber.js:60
next @ Subscriber.js:31
(anonym) @ Subject.js:34
errorContext @ errorContext.js:19
next @ Subject.js:27
emit @ core.mjs:22117
(anonym) @ core.mjs:25646
invoke @ zone.js:375
run @ zone.js:134
runOutsideAngular @ core.mjs:25519
onHandleError @ core.mjs:25646
handleError @ zone.js:379
runGuarded @ zone.js:147
api.microtaskDrainDone @ zone.js:1075
drainMicroTaskQueue @ zone.js:595
Promise.then (async)
nativeScheduleMicroTask @ zone.js:564
scheduleMicroTask @ zone.js:575
scheduleTask @ zone.js:399
scheduleTask @ zone.js:221
scheduleMicroTask @ zone.js:241
scheduleResolveOrReject @ zone.js:1268
then @ zone.js:1464
bootstrapModule @ core.mjs:26344
4431 @ main.ts:6
__webpack_require__ @ bootstrap:19
__webpack_exec__ @ main.ts:7
(anonym) @ main.ts:7
__webpack_require__.O @ chunk loaded:23
(anonym) @ main.ts:7
webpackJsonpCallback @ jsonp chunk loading:34
(anonym) @ main.js:2
16 weitere Frames anzeigen
```


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

```true
Angular CLI: 15.0.4
Node: 16.13.0
Package Manager: npm 8.1.0
OS: darwin x64

Angular: 15.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.4
@angular-devkit/build-angular   15.0.4
@angular-devkit/core            15.0.4
@angular-devkit/schematics      15.0.4
@schematics/angular             15.0.4
rxjs                            7.5.7
typescript                      4.8.4
```


### Anything else?

_No response_