How to access dynamic segment in a controller in Ember.js?

前端 未结 4 1442
余生分开走
余生分开走 2021-02-14 01:07

I have an example route:

this.route(\'client\', {path: \':id\'});

I can access this in my route like this:

model: function(para         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-02-14 01:58

    This is how I do it in my application. Not sure if this is the best approach.

    App.IndexRoute = Em.Route.extend({
      model: function(params) {
        this.set('params', params);
      },
      setupController: function(controller, model) {
        controller.set('params', this.get('params'));
        this._super(controller, model);
      }
    });
    

    Alternatively you can also do a lookup on the container inside your controller. But I dont really think this is a good approach. Here is an example.

    this.get('container').lookup('router:main').router.currentHandlerInfos
            .findBy('name','index').params
    

提交回复
热议问题