How to save path and return to it with Ember V2 Router

So, I am having problems with the new Ember router. I am trying to save and later revert to the current path for a given dynamic segment, so my urls might look like

#/inventory/vehicle/1001

      

which can then separate into

#/inventory/vehicle/1001/details
#/inventory/vehicle/1001/photos
#/inventory/vehicle/1001/description

      

etc .. I need a way to go back to the most recent route. The Ember manual has a method to do this here:

http://emberjs.com/guides/routing/redirection/

The problem with this method is that by creating the route "/ choose" and assigning it to "/", this overwrites the default route "/ inventory / vehicle / 1001". For example, if I tried to link to a vehicle like this:

{{#linkTo "vehicle" vehicle}}

      

Then Ember throws an error because the "car" route no longer exists. Instead, it should be installed:

{{#linkTo "vehicle.choose" vehicle}}

      

What works is activating VehicleChooseRoute and all. Also, since "vehicle.choose" is technically a child of a "vehicle", #linkTo ONLY has an active class applied when the current route

#/inventory/vehicle/1001

      

Which is instantly redirected to the last filter, and so it's basically never included. So basically I'm trying to find a way to get around this. I tried changing the "vehicle.choose" path to be the default path (# / inventory / vehicle / 1001 / choose) so that it doesn't overwrite the "car" route, and then set up VehicleRoute like this:

Case.Router.map(function() {
  this.resource('inventory', function(){
    this.route('review');
    this.route('sheets');
    this.resource('vehicle', { path: '/vehicle/:vehicle_id' }, function(){
      this.route('choose');
      this.route('details');
      this.route('consignor');
      this.route('additional');
      this.route('price');
      this.route('dmv');
      this.route('expenses');
      this.route('description');
      this.route('tasks');
    });
  });
});

App.VehicleRoute = Ember.Route.extend({
  model: function(params) {
    return Case.Vehicle.find(params.vehicle_id);
  },
  setupController: function(controller, model) {
    model.set('active', true);
  },
  redirect: function() {
    this.transitionTo('vehicle.choose');
  }
})

Case.VehicleChooseRoute = Ember.Route.extend({
  redirect: function() {
    var lastFilter = this.controllerFor('vehicle').get('lastFilter');
    this.transitionTo('vehicle.' + (lastFilter || 'details'));
  }
});

      

But the problem that comes from this (besides feeling like it's hacked together) is that the redirect replaces the entire template that would normally be rendered by "vehicle", so I only get the view. So not an option.

+3


source to share





All Articles