简体   繁体   English

ID为ember-cli的路由

[英]Route with ID in ember-cli

I'm trying to generate a settings page for my Ember-Cli app. 我正在尝试为我的Ember-Cli应用程序生成一个设置页面。 The URL I would like is /settings/:id/ with separate routes such as /settings/:id/overview and /settings/:id/password . 我想要的URL是/settings/:id/带有单独的路由,例如/settings/:id/overview/settings/:id/password

How do I create nested routes using Ember CLI? 如何使用Ember CLI创建嵌套路由? I've found plenty of examples for Ember, but not for CLI. 我找到了很多关于Ember的示例,但没有找到关于CLI的示例。

UPDATE: As of v0.1.5, Ember-CLI has fixed the issue with not generating the routing map correctly. 更新:从v0.1.5开始,Ember-CLI解决了无法正确生成路由映射的问题。 Running the commands below should now generate the correct code in router.js . 现在,运行以下命令应该会在router.js生成正确的代码。 It also added a path option for nested routes (rather than resources). 它还为嵌套路由(而不是资源)添加了path选项。 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). 目前,还没有办法使用Ember-CLI完全生成嵌套的路由或资源(据我所知)。 You can have it generate the files for you, but you'll have to edit router.js yourself. 您可以让它为您生成文件,但是您必须自己编辑router.js 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.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.js即可嵌套路由调用,而不是使其成为顶级路由:

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. 我只是生成资源,然后手动将其更改为路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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