Skip to content

Commit c3fd9c7

Browse files
committed
feat: allow lazy route prefix to be configurable
Fixes #842
1 parent c92f330 commit c3fd9c7

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

addon/ng2/blueprints/component/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ module.exports = {
8686
dir += path.sep + options.dasherizedModuleName;
8787

8888
if (options.locals.isLazyRoute) {
89+
var lazyRoutePrefix = '+';
90+
if (this.project.ngConfig &&
91+
this.project.ngConfig.defaults &&
92+
this.project.ngConfig.defaults.lazyRoutePrefix !== undefined) {
93+
lazyRoutePrefix = this.project.ngConfig.defaults.lazyRoutePrefix;
94+
}
8995
var dirParts = dir.split(path.sep);
90-
dirParts[dirParts.length - 1] = `+${dirParts[dirParts.length - 1]}`;
96+
dirParts[dirParts.length - 1] = `${lazyRoutePrefix}${dirParts[dirParts.length - 1]}`;
9197
dir = dirParts.join(path.sep);
9298
}
9399
}

addon/ng2/blueprints/ng2/files/angular-cli.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"prefix": "<%= prefix %>",
2727
"sourceDir": "<%= sourceDir %>",
2828
"styleExt": "<%= styleExt %>",
29-
"prefixInterfaces": false
29+
"prefixInterfaces": false,
30+
"lazyRoutePrefix": "+"
3031
}
3132
}

addon/ng2/blueprints/route/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,14 @@ module.exports = {
229229

230230
// Insert the import statement.
231231
let content = fs.readFileSync(parentFile, 'utf-8');
232+
let lazyRoutePrefix = '+';
233+
if (this.project.ngConfig &&
234+
this.project.ngConfig.defaults &&
235+
this.project.ngConfig.defaults.lazyRoutePrefix !== undefined) {
236+
lazyRoutePrefix = this.project.ngConfig.defaults.lazyRoutePrefix;
237+
}
232238
content = _insertImport(content, `${jsComponentName}Component`,
233-
`./${options.isLazyRoute ? '+' : ''}${stringUtils.dasherize(base)}`);
239+
`./${options.isLazyRoute ? lazyRoutePrefix : ''}${stringUtils.dasherize(base)}`);
234240

235241
let defaultReg = options.default ? ', useAsDefault: true' : '';
236242
let routePath = options.path || `/${base}`;

lib/config/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
},
9393
"prefixInterfaces": {
9494
"type": "boolean"
95+
},
96+
"lazyRoutePrefix": {
97+
"type": "string"
9598
}
9699
},
97100
"additionalProperties": false

tests/acceptance/generate-route.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,14 @@ describe('Acceptance: ng generate route', function () {
102102
expect(afterGenerateParentHtml).to.equal(unmodifiedParentComponentHtml);
103103
});
104104
});
105+
106+
it('lazy route prefix', () => {
107+
return ng(['set', 'defaults.lazyRoutePrefix', 'myprefix'])
108+
.then(() => ng(['generate', 'route', 'prefix-test']))
109+
.then(() => {
110+
var folderPath = path.join(testPath, 'myprefixprefix-test', 'prefix-test.component.ts');
111+
expect(existsSync(folderPath))
112+
.to.equal(true);
113+
});
114+
});
105115
});

0 commit comments

Comments
 (0)