Search code examples
ember-cli

dynamic segments is not working


I have setup the following route in router.js:

this.route('reports',{path:'/reports/:report_name'}, function(){

});

I have following link setup in on of the hbs file:

{{#link-to 'reports' 'eod-2015'}}EOD 2015{{/link-to}}

in app/route/reports/index.js

model: function(params) {
  console.log(params);
}

and I am getting {} as a result, how can I find report_name in my index.js route in app/route/reports folder?


Solution

  • Instead of trying to access param in app/route/reports/index.js you should access it in app/route/reports.js.

    See demo.

    Comparison:

    Inside reports.js file: Object {report_name: "eod-2015"}

    Inside index.js file: Object {}

    If you would like to access reports params inside reports.index route you could do:

    model(params) {
      const parentParams = this.paramsFor('reports');
      console.log('Accessing reports.js from index.js:', parentParams);
    }