Ember Query Params


#1

In my application I want to read the parameters user is entering and then I want to use that parameter. http://responsive.beta.postify.com/X I want to read that X value. But first how do I ensure that the router expects a parameter?

My router is like this

Cards.Router.map(function ()
{
this.resource('cards', {path: '/'}, function ()
{
  // additional child routes
  this.resource('selectImage');
  this.resource('message');
  this.resource('recipient');
  this.resource('orderStatus');
  this.resource('thankyou');
  this.resource('accountInfo');
  this.resource('recentOrders');
  this.resource('howTo');
  this.resource('faq');

   });

});

I want that parameter whenever the app loads. That is going to be my clientID which I would be using to fetch data from server depending upon the client.

Any thoughts on it?


#2

Try having a route with the client id in the path, then in the model you can setup your client however you want and child routes can access that model.

So define your routes like:

App.Router.map(function() {
  this.resource('client', {path: '/:clientId'}, function() {
    this.route('selectedImage');
  });
});

and set the model for the client like so:

App.ClientRoute = Ember.Route.extend({
  model: function(params) {
    return {name: "hello", id: params.clientId};
  }
});

Inside the child route (for example ‘selectedImage’ route):

App.ClientSelectedImageRoute = Ember.Route.extend({
  model: function() {
    var client = this.modelFor('client');
    // here you can use client.id to fetch whatever data
  }
});

see this jsbin for a working example: http://emberjs.jsbin.com/baroxije/3/edit