dimanche 28 juin 2015

Kayak like URL instead of query parameters

I have a small app which reads parameters from the URL.

Example: http://localhost:4200/flights?from=FRA&to=JFK

I'd like to offer the user a Kayak like URL like: http://localhost:4200/flights/FRA-JFK

Can this be done with Ember without doing the mapping in the webserver?

app/controllers/flights.js

import Ember from 'ember';

export default Ember.Controller.extend({
  queryParams: ['from','to'],
  from: null,
  to: null,

  filteredFromFlights: function() {
    var from = this.get('from');
    var flights = this.get('model');

    if (from) {
      return flights.filterBy('from', from);
    } else {
      return flights;
    }
  }.property('from', 'to', 'model'),

  filteredFlights: function() {
    var to = this.get('to');
    var flights = this.get('filteredFromFlights');

    if (to) {
      return flights.filterBy('to', to);
    } else {
      return flights;
    }
  }.property('from', 'to', 'model')
});




Aucun commentaire:

Enregistrer un commentaire