File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313 inject ,
1414 provideEnvironmentInitializer ,
1515} from '@angular/core' ;
16+ import { UrlSerializer } from '@angular/router' ;
1617import {
1718 DOCS_CONTENT_LOADER ,
1819 ENVIRONMENT ,
@@ -31,6 +32,7 @@ import {CustomErrorHandler} from './core/services/errors-handling/error-handler'
3132import { ExampleContentLoader } from './core/services/example-content-loader.service' ;
3233import { routerProviders } from './routing/router_providers' ;
3334import { TYPESCRIPT_VFS_WORKER_PROVIDER } from './editor/code-editor/workers/factory-provider' ;
35+ import { AdevUrlSerializer } from './core/services/routing/adev-url-serializer' ;
3436
3537export const appConfig : ApplicationConfig = {
3638 providers : [
@@ -49,5 +51,9 @@ export const appConfig: ApplicationConfig = {
4951 deps : [ DOCUMENT ] ,
5052 } ,
5153 TYPESCRIPT_VFS_WORKER_PROVIDER ,
54+ {
55+ provide : UrlSerializer ,
56+ useClass : AdevUrlSerializer ,
57+ } ,
5258 ] ,
5359} ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @license
3+ * Copyright Google LLC All Rights Reserved.
4+ *
5+ * Use of this source code is governed by an MIT-style license that can be
6+ * found in the LICENSE file at https://angular.dev/license
7+ */
8+
9+ import { DefaultUrlSerializer , UrlTree } from '@angular/router' ;
10+
11+ /**
12+ * Custom URL serializer extending the default behavior
13+ * with Adev-specific behavior.
14+ */
15+ export class AdevUrlSerializer extends DefaultUrlSerializer {
16+ override parse ( url : string ) : UrlTree {
17+ // Since the app host/server is decoding encoded forward slashes,
18+ // we perform this on the client as well in order to maintain
19+ // a consistent behavior between the two environments and
20+ // avoid opening a different page on client hydration (presumably, 404).
21+ url = url . replaceAll ( / % 2 ( F | f ) / g, '/' ) ;
22+
23+ return super . parse ( url ) ;
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * @license
3+ * Copyright Google LLC All Rights Reserved.
4+ *
5+ * Use of this source code is governed by an MIT-style license that can be
6+ * found in the LICENSE file at https://angular.dev/license
7+ */
8+
9+ import { TestBed } from '@angular/core/testing' ;
10+ import { UrlSerializer } from '@angular/router' ;
11+ import { AdevUrlSerializer } from './adev-url-serializer' ;
12+
13+ describe ( 'AdevUrlSerializer' , ( ) => {
14+ let serializer : UrlSerializer ;
15+
16+ beforeEach ( ( ) => {
17+ TestBed . configureTestingModule ( {
18+ providers : [
19+ {
20+ provide : UrlSerializer ,
21+ useClass : AdevUrlSerializer ,
22+ } ,
23+ ] ,
24+ } ) ;
25+
26+ serializer = TestBed . inject ( UrlSerializer ) ;
27+ } ) ;
28+
29+ it ( 'should decode encoded forward slash (%2F)' , ( ) => {
30+ // Uppercase hex
31+ expect ( serializer . parse ( 'page%2Fabout' ) . toString ( ) ) . toBe ( '/page/about' ) ;
32+
33+ // Lowercase hex
34+ expect ( serializer . parse ( 'page%2fabout' ) . toString ( ) ) . toBe ( '/page/about' ) ;
35+ } ) ;
36+ } ) ;
You can’t perform that action at this time.
0 commit comments