Skip to content

Commit 5a3f06b

Browse files
Broccofilipesilva
authored andcommitted
feat: add ability to specify a path when generating a route (#561)
1 parent 2f4ff82 commit 5a3f06b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

addon/ng2/blueprints/route/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ module.exports = {
106106
{ name: 'lazy', type: Boolean, default: true },
107107
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] },
108108
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
109-
{ name: 'prefix', type: Boolean, default: true }
109+
{ name: 'prefix', type: Boolean, default: true },
110+
{ name: 'path', type: String }
110111
],
111112

112113
beforeInstall: function(options) {
@@ -222,8 +223,9 @@ module.exports = {
222223
`./${options.isLazyRoute ? '+' : ''}${base}`);
223224

224225
let defaultReg = options.default ? ', useAsDefault: true' : '';
226+
let path = options.path || `/${base}`;
225227
let route = '{'
226-
+ `path: '/${base}', `
228+
+ `path: '${path}', `
227229
+ `name: '${jsComponentName}', `
228230
+ `component: ${jsComponentName}Component`
229231
+ defaultReg

tests/acceptance/generate-route.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,12 @@ describe('Acceptance: ng generate route', function () {
8181
expect(myThirdRouteContent).to.not.include('@RouteConfig');
8282
});
8383
});
84+
85+
it('ng generate route details --path /details/:id', () => {
86+
return ng(['generate', 'route', 'details', '--path', '/details/:id'])
87+
.then(() => {
88+
const appContent = fs.readFileSync(path.join(testPath, 'foo.component.ts'), 'utf-8');
89+
expect(appContent).to.match(/path: '\/details\/:id'/m);
90+
});
91+
});
8492
});

0 commit comments

Comments
 (0)