@@ -16,9 +16,8 @@ import {navigationCancelingError} from './navigation_canceling_error';
16
16
import { Params , PRIMARY_OUTLET } from './shared' ;
17
17
import { UrlSegment , UrlSegmentGroup , UrlSerializer , UrlTree } from './url_tree' ;
18
18
19
-
20
19
export class NoMatch {
21
- public segmentGroup : UrlSegmentGroup | null ;
20
+ public segmentGroup : UrlSegmentGroup | null ;
22
21
23
22
constructor ( segmentGroup ?: UrlSegmentGroup ) {
24
23
this . segmentGroup = segmentGroup || null ;
@@ -40,23 +39,30 @@ export function absoluteRedirect(newTree: UrlTree): Observable<any> {
40
39
}
41
40
42
41
export function namedOutletsRedirect ( redirectTo : string ) : Observable < any > {
43
- return throwError ( new RuntimeError (
42
+ return throwError (
43
+ new RuntimeError (
44
44
RuntimeErrorCode . NAMED_OUTLET_REDIRECT ,
45
45
( typeof ngDevMode === 'undefined' || ngDevMode ) &&
46
- `Only absolute redirects can have named outlets. redirectTo: '${ redirectTo } '` ) ) ;
46
+ `Only absolute redirects can have named outlets. redirectTo: '${ redirectTo } '` ,
47
+ ) ,
48
+ ) ;
47
49
}
48
50
49
51
export function canLoadFails ( route : Route ) : Observable < LoadedRouterConfig > {
50
- return throwError ( navigationCancelingError (
52
+ return throwError (
53
+ navigationCancelingError (
51
54
( typeof ngDevMode === 'undefined' || ngDevMode ) &&
52
- `Cannot load children because the guard of the route "path: '${
53
- route . path } '" returned false`,
54
- NavigationCancellationCode . GuardRejected ) ) ;
55
+ `Cannot load children because the guard of the route "path: '${ route . path } '" returned false` ,
56
+ NavigationCancellationCode . GuardRejected ,
57
+ ) ,
58
+ ) ;
55
59
}
56
60
57
-
58
61
export class ApplyRedirects {
59
- constructor ( private urlSerializer : UrlSerializer , private urlTree : UrlTree ) { }
62
+ constructor (
63
+ private urlSerializer : UrlSerializer ,
64
+ private urlTree : UrlTree ,
65
+ ) { }
60
66
61
67
lineralizeSegments ( route : Route , urlTree : UrlTree ) : Observable < UrlSegment [ ] > {
62
68
let res : UrlSegment [ ] = [ ] ;
@@ -76,22 +82,34 @@ export class ApplyRedirects {
76
82
}
77
83
78
84
applyRedirectCommands (
79
- segments : UrlSegment [ ] , redirectTo : string , posParams : { [ k : string ] : UrlSegment } ) : UrlTree {
85
+ segments : UrlSegment [ ] ,
86
+ redirectTo : string ,
87
+ posParams : { [ k : string ] : UrlSegment } ,
88
+ ) : UrlTree {
80
89
const newTree = this . applyRedirectCreateUrlTree (
81
- redirectTo , this . urlSerializer . parse ( redirectTo ) , segments , posParams ) ;
90
+ redirectTo ,
91
+ this . urlSerializer . parse ( redirectTo ) ,
92
+ segments ,
93
+ posParams ,
94
+ ) ;
82
95
if ( redirectTo . startsWith ( '/' ) ) {
83
96
throw new AbsoluteRedirect ( newTree ) ;
84
97
}
85
98
return newTree ;
86
99
}
87
100
88
101
applyRedirectCreateUrlTree (
89
- redirectTo : string , urlTree : UrlTree , segments : UrlSegment [ ] ,
90
- posParams : { [ k : string ] : UrlSegment } ) : UrlTree {
102
+ redirectTo : string ,
103
+ urlTree : UrlTree ,
104
+ segments : UrlSegment [ ] ,
105
+ posParams : { [ k : string ] : UrlSegment } ,
106
+ ) : UrlTree {
91
107
const newRoot = this . createSegmentGroup ( redirectTo , urlTree . root , segments , posParams ) ;
92
108
return new UrlTree (
93
- newRoot , this . createQueryParams ( urlTree . queryParams , this . urlTree . queryParams ) ,
94
- urlTree . fragment ) ;
109
+ newRoot ,
110
+ this . createQueryParams ( urlTree . queryParams , this . urlTree . queryParams ) ,
111
+ urlTree . fragment ,
112
+ ) ;
95
113
}
96
114
97
115
createQueryParams ( redirectToParams : Params , actualParams : Params ) : Params {
@@ -109,8 +127,11 @@ export class ApplyRedirects {
109
127
}
110
128
111
129
createSegmentGroup (
112
- redirectTo : string , group : UrlSegmentGroup , segments : UrlSegment [ ] ,
113
- posParams : { [ k : string ] : UrlSegment } ) : UrlSegmentGroup {
130
+ redirectTo : string ,
131
+ group : UrlSegmentGroup ,
132
+ segments : UrlSegment [ ] ,
133
+ posParams : { [ k : string ] : UrlSegment } ,
134
+ ) : UrlSegmentGroup {
114
135
const updatedSegments = this . createSegments ( redirectTo , group . segments , segments , posParams ) ;
115
136
116
137
let children : { [ n : string ] : UrlSegmentGroup } = { } ;
@@ -122,22 +143,30 @@ export class ApplyRedirects {
122
143
}
123
144
124
145
createSegments (
125
- redirectTo : string , redirectToSegments : UrlSegment [ ] , actualSegments : UrlSegment [ ] ,
126
- posParams : { [ k : string ] : UrlSegment } ) : UrlSegment [ ] {
127
- return redirectToSegments . map (
128
- s => s . path . startsWith ( ':' ) ? this . findPosParam ( redirectTo , s , posParams ) :
129
- this . findOrReturn ( s , actualSegments ) ) ;
146
+ redirectTo : string ,
147
+ redirectToSegments : UrlSegment [ ] ,
148
+ actualSegments : UrlSegment [ ] ,
149
+ posParams : { [ k : string ] : UrlSegment } ,
150
+ ) : UrlSegment [ ] {
151
+ return redirectToSegments . map ( ( s ) =>
152
+ s . path . startsWith ( ':' )
153
+ ? this . findPosParam ( redirectTo , s , posParams )
154
+ : this . findOrReturn ( s , actualSegments ) ,
155
+ ) ;
130
156
}
131
157
132
158
findPosParam (
133
- redirectTo : string , redirectToUrlSegment : UrlSegment ,
134
- posParams : { [ k : string ] : UrlSegment } ) : UrlSegment {
159
+ redirectTo : string ,
160
+ redirectToUrlSegment : UrlSegment ,
161
+ posParams : { [ k : string ] : UrlSegment } ,
162
+ ) : UrlSegment {
135
163
const pos = posParams [ redirectToUrlSegment . path . substring ( 1 ) ] ;
136
164
if ( ! pos )
137
165
throw new RuntimeError (
138
- RuntimeErrorCode . MISSING_REDIRECT ,
139
- ( typeof ngDevMode === 'undefined' || ngDevMode ) &&
140
- `Cannot redirect to '${ redirectTo } '. Cannot find '${ redirectToUrlSegment . path } '.` ) ;
166
+ RuntimeErrorCode . MISSING_REDIRECT ,
167
+ ( typeof ngDevMode === 'undefined' || ngDevMode ) &&
168
+ `Cannot redirect to '${ redirectTo } '. Cannot find '${ redirectToUrlSegment . path } '.` ,
169
+ ) ;
141
170
return pos ;
142
171
}
143
172
0 commit comments