diff --git a/addon/ng2/blueprints/component/index.js b/addon/ng2/blueprints/component/index.js index 58950e13d396..750b8beb25eb 100644 --- a/addon/ng2/blueprints/component/index.js +++ b/addon/ng2/blueprints/component/index.js @@ -86,8 +86,14 @@ module.exports = { dir += path.sep + options.dasherizedModuleName; if (options.locals.isLazyRoute) { + var lazyRoutePrefix = '+'; + if (this.project.ngConfig && + this.project.ngConfig.defaults && + this.project.ngConfig.defaults.lazyRoutePrefix !== undefined) { + lazyRoutePrefix = this.project.ngConfig.defaults.lazyRoutePrefix; + } var dirParts = dir.split(path.sep); - dirParts[dirParts.length - 1] = `+${dirParts[dirParts.length - 1]}`; + dirParts[dirParts.length - 1] = `${lazyRoutePrefix}${dirParts[dirParts.length - 1]}`; dir = dirParts.join(path.sep); } } diff --git a/addon/ng2/blueprints/ng2/files/angular-cli.json b/addon/ng2/blueprints/ng2/files/angular-cli.json index d6987fb768d4..5b96ba0ba88c 100644 --- a/addon/ng2/blueprints/ng2/files/angular-cli.json +++ b/addon/ng2/blueprints/ng2/files/angular-cli.json @@ -26,6 +26,7 @@ "prefix": "<%= prefix %>", "sourceDir": "<%= sourceDir %>", "styleExt": "<%= styleExt %>", - "prefixInterfaces": false + "prefixInterfaces": false, + "lazyRoutePrefix": "+" } } diff --git a/addon/ng2/blueprints/route/index.js b/addon/ng2/blueprints/route/index.js index 780de6a19d32..c3096acb8fb3 100644 --- a/addon/ng2/blueprints/route/index.js +++ b/addon/ng2/blueprints/route/index.js @@ -229,8 +229,14 @@ module.exports = { // Insert the import statement. let content = fs.readFileSync(parentFile, 'utf-8'); + let lazyRoutePrefix = '+'; + if (this.project.ngConfig && + this.project.ngConfig.defaults && + this.project.ngConfig.defaults.lazyRoutePrefix !== undefined) { + lazyRoutePrefix = this.project.ngConfig.defaults.lazyRoutePrefix; + } content = _insertImport(content, `${jsComponentName}Component`, - `./${options.isLazyRoute ? '+' : ''}${stringUtils.dasherize(base)}`); + `./${options.isLazyRoute ? lazyRoutePrefix : ''}${stringUtils.dasherize(base)}`); let defaultReg = options.default ? ', useAsDefault: true' : ''; let routePath = options.path || `/${base}`; diff --git a/lib/config/schema.json b/lib/config/schema.json index 08db591b3809..d8598052dd14 100644 --- a/lib/config/schema.json +++ b/lib/config/schema.json @@ -92,6 +92,9 @@ }, "prefixInterfaces": { "type": "boolean" + }, + "lazyRoutePrefix": { + "type": "string" } }, "additionalProperties": false diff --git a/tests/acceptance/generate-route.spec.js b/tests/acceptance/generate-route.spec.js index ce665427a56d..9610185b7179 100644 --- a/tests/acceptance/generate-route.spec.js +++ b/tests/acceptance/generate-route.spec.js @@ -102,4 +102,14 @@ describe('Acceptance: ng generate route', function () { expect(afterGenerateParentHtml).to.equal(unmodifiedParentComponentHtml); }); }); + + it('lazy route prefix', () => { + return ng(['set', 'defaults.lazyRoutePrefix', 'myprefix']) + .then(() => ng(['generate', 'route', 'prefix-test'])) + .then(() => { + var folderPath = path.join(testPath, 'myprefixprefix-test', 'prefix-test.component.ts'); + expect(existsSync(folderPath)) + .to.equal(true); + }); + }); });