简体   繁体   中英

Route with ID in ember-cli

I'm trying to generate a settings page for my Ember-Cli app. The URL I would like is /settings/:id/ with separate routes such as /settings/:id/overview and /settings/:id/password .

How do I create nested routes using Ember CLI? I've found plenty of examples for Ember, but not for CLI.

UPDATE: As of v0.1.5, Ember-CLI has fixed the issue with not generating the routing map correctly. Running the commands below should now generate the correct code in router.js . It also added a path option for nested routes (rather than resources). You can see the changelog here . It looks as if the changelog notes are currently the only documentation of that feature, but they're easy enough to understand.


Right now, there is no way to fully generate nested routes or resources with Ember-CLI (as far as I can tell). You can have it generate the files for you, but you'll have to edit router.js yourself. For instance, if I run the following lines:

ember generate resource settings
ember generate route settings/overview

You'll get the following router.js :

Router.map(function() {
    this.resource('settings', { path: 'settings/:settings_id' }, function() { });
    this.route('settings/overview');
});

This is probably just a limitation in the way Blueprints currently works. Go ahead and generate your routes as you see above, then just modify router.js by hand to nest the route calls instead of making them top-level:

Router.map(function() {
    this.resource('settings', { path: 'settings/:settings_id' }, function() {
        this.route('overview');
    });
});

Also, if you want to create a nested route, not a nested resource, I'm not sure there is a blueprint for that yet. I would just generate a resource and then change it to a route manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM