@@ -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,8 @@ module.exports = {
214
213
return ;
215
214
}
216
215
216
+ const isAppComponent = ( parentFile == path . join ( this . dynamicPath . dir , this . project . name ( ) + '.component.ts' ) ) ;
217
+
217
218
const jsComponentName = stringUtils . classify ( options . entity . name ) ;
218
219
const base = parsedPath . base ;
219
220
@@ -263,25 +264,28 @@ module.exports = {
263
264
}
264
265
} ) ;
265
266
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
- }
267
+ // Add the provider, only on the APP itself.
268
+ if ( isAppComponent ) {
269
+ content = _insertImport ( content , 'ROUTER_DIRECTIVES' , 'angular2/router' ) ;
270
+ content = content . replace ( / ( @ C o m p o n e n t \( \{ ) ( [ \s \S \n ] * ?) ( \n \} \) ) / m, function ( _ , prefix , json , suffix ) {
271
+ const m = json . match ( / ( ^ \s + p r o v i d e r s : \s * \[ ) ( [ \s \S \n ] * ) ( \] \s * , ? .* $ ) / m) ;
272
+ if ( m ) {
273
+ if ( m [ 2 ] . indexOf ( 'ROUTER_PROVIDERS' ) != - 1 ) {
274
+ // Already there.
275
+ return _ ;
276
+ }
274
277
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
- } ) ;
278
+ // There's a directive already, but no ROUTER_PROVIDERS.
279
+ return prefix +
280
+ json . replace ( / ( ^ \s + p r o v i d e r s : \s * \[ ) ( [ \s \S \n ] * ) ( ^ \] \s * , ? .* $ ) / m, function ( _ , prefix , d , suffix ) {
281
+ return prefix + d + ( d ? ',' : '' ) + 'ROUTER_PROVIDERS' + suffix ;
282
+ } ) + suffix ;
283
+ } else {
284
+ // There's no directive already.
285
+ return prefix + json + ',\n providers: [ROUTER_PROVIDERS]' + suffix ;
286
+ }
287
+ } ) ;
288
+ }
285
289
286
290
// Change the template.
287
291
content = content . replace ( / ( @ C o m p o n e n t \( \{ ) ( [ \s \S \n ] * ?) ( \} \) ) / m, function ( _ , prefix , json , suffix ) {
0 commit comments