Ember中的嵌套路线 [英] Nested routes in Ember

查看:98
本文介绍了Ember中的嵌套路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的设置区域如下所示:

I want my settings area to look like this:

..
/settings/:accountId/users
/settings/:accountId/users/:userId

我的路由器定义如下:

I have my router defined as follows:

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

这用于显示用户列表页面。我不知道如何把它带到下一步,同时拥有 / users / users / 1

This works for displaying the users listing page. I'm not sure how to take it to the next step though and have both a route and a resource for /users and /users/1.

谢谢。

推荐答案

最新版本的Ember,路由可以有子路由(为命名空间)。

In the latest versions of Ember, route's can have sub routes (for namespace sake).

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

http://emberjs.jsbin.com/cutayuniga/1/edit?html,js,output

如果你是一个较旧的版本,你将不得不为用户提供资源。

If you're in an older version, you will have to make users a resource.

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

这篇关于Ember中的嵌套路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆