@@ -79,7 +79,6 @@ function _addRouteConfig(content) {
79
79
// Add the imports.
80
80
content = _insertImport ( content , 'RouteConfig' , 'angular2/router' ) ;
81
81
content = _insertImport ( content , 'ROUTER_DIRECTIVES' , 'angular2/router' ) ;
82
- content = _insertImport ( content , 'ROUTER_PROVIDERS' , 'angular2/router' ) ;
83
82
84
83
// Add the router config.
85
84
const m = content . match ( / ( @ C o m p o n e n t \( \{ [ \s \S \n ] * ?} \) \n ) ( \s * e x p o r t c l a s s ) / m) ;
@@ -214,6 +213,11 @@ module.exports = {
214
213
return ;
215
214
}
216
215
216
+ let isAppComponent = false ;
217
+ if ( parentFile == path . join ( this . dynamicPath . dir , this . project . name ( ) + '.component.ts' ) ) {
218
+ isAppComponent = true ;
219
+ }
220
+
217
221
const jsComponentName = stringUtils . classify ( options . entity . name ) ;
218
222
const base = parsedPath . base ;
219
223
@@ -223,9 +227,9 @@ module.exports = {
223
227
`./${ options . isLazyRoute ? '+' : '' } ${ base } ` ) ;
224
228
225
229
let defaultReg = options . default ? ', useAsDefault: true' : '' ;
226
- let path = options . path || `/${ base } ` ;
230
+ let routePath = options . path || `/${ base } ` ;
227
231
let route = '{'
228
- + `path: '${ path } ', `
232
+ + `path: '${ routePath } ', `
229
233
+ `name: '${ jsComponentName } ', `
230
234
+ `component: ${ jsComponentName } Component`
231
235
+ defaultReg
@@ -263,25 +267,28 @@ module.exports = {
263
267
}
264
268
} ) ;
265
269
266
- // Add the provider.
267
- content = content . replace ( / ( @ C o m p o n e n t \( \{ ) ( [ \s \S \n ] * ?) ( \n \} \) ) / m, function ( _ , prefix , json , suffix ) {
268
- const m = json . match ( / ( ^ \s + p r o v i d e r s : \s * \[ ) ( [ \s \S \n ] * ) ( \] \s * , ? .* $ ) / m) ;
269
- if ( m ) {
270
- if ( m [ 2 ] . indexOf ( 'ROUTER_PROVIDERS' ) != - 1 ) {
271
- // Already there.
272
- return _ ;
273
- }
270
+ // Add the provider, only on the APP itself.
271
+ if ( isAppComponent ) {
272
+ content = _insertImport ( content , 'ROUTER_DIRECTIVES' , 'angular2/router' ) ;
273
+ content = content . replace ( / ( @ C o m p o n e n t \( \{ ) ( [ \s \S \n ] * ?) ( \n \} \) ) / m, function ( _ , prefix , json , suffix ) {
274
+ const m = json . match ( / ( ^ \s + p r o v i d e r s : \s * \[ ) ( [ \s \S \n ] * ) ( \] \s * , ? .* $ ) / m) ;
275
+ if ( m ) {
276
+ if ( m [ 2 ] . indexOf ( 'ROUTER_PROVIDERS' ) != - 1 ) {
277
+ // Already there.
278
+ return _ ;
279
+ }
274
280
275
- // There's a directive already, but no ROUTER_PROVIDERS.
276
- return prefix +
277
- json . replace ( / ( ^ \s + p r o v i d e r s : \s * \[ ) ( [ \s \S \n ] * ) ( ^ \] \s * , ? .* $ ) / m, function ( _ , prefix , d , suffix ) {
278
- return prefix + d + ( d ? ',' : '' ) + 'ROUTER_PROVIDERS' + suffix ;
279
- } ) + suffix ;
280
- } else {
281
- // There's no directive already.
282
- return prefix + json + ',\n providers: [ROUTER_PROVIDERS]' + suffix ;
283
- }
284
- } ) ;
281
+ // There's a directive already, but no ROUTER_PROVIDERS.
282
+ return prefix +
283
+ json . replace ( / ( ^ \s + p r o v i d e r s : \s * \[ ) ( [ \s \S \n ] * ) ( ^ \] \s * , ? .* $ ) / m, function ( _ , prefix , d , suffix ) {
284
+ return prefix + d + ( d ? ',' : '' ) + 'ROUTER_PROVIDERS' + suffix ;
285
+ } ) + suffix ;
286
+ } else {
287
+ // There's no directive already.
288
+ return prefix + json + ',\n providers: [ROUTER_PROVIDERS]' + suffix ;
289
+ }
290
+ } ) ;
291
+ }
285
292
286
293
// Change the template.
287
294
content = content . replace ( / ( @ C o m p o n e n t \( \{ ) ( [ \s \S \n ] * ?) ( \} \) ) / m, function ( _ , prefix , json , suffix ) {
0 commit comments