lundi 9 novembre 2015

Ember router transitions to route that doesn't exist

I am having an issues with my ember app that whenever the login page loads in just once I can log in just fine and it takes me to the correct page. However, when I refresh the login page and then log in, it takes me to a strange route that is not set up in my router.

The correct transition should be login -> authenticated.individual.info

But the route it takes me to is login -> login.individual.info

I'm really confused as to what would cause the router to send me to a route that doesn't exist, or maybe I'm just not very familiar with how routers work.

app/router.js

Router.map(function() {
  this.route('authenticated', { path: '/:slug' }, function() {
    this.resource('individual',  { path: 'individual/:id' }, function() {
      this.route('info');
    });
  });
  this.route('login', { path: 'login/:slug' });
});

The slug is essentially a personal shortname connected to each user's data of their member's information.

app/login/route.js

import Ember from 'ember';
var bind = Ember.run.bind;

export default Ember.Route.extend({
  model: function(params) {
    return {'slug': params.slug};
  },

  actions: {
    login: function(credentials) {
      this.get('session').login(credentials)
        .then(bind(this, 'authenticationDidSucceed'),
              bind(this, 'authenticationDidFail'));
    }
  },

  authenticationDidSucceed: function() {
    var transition = this.get('controller.attemptedTransition');
    var individual_id = this.get('session').individual_id;
    if (transition) {
      transition.retry();
    } else {
      this.transitionTo('individual.info', individual_id);
    }
  },

  authenticationDidFail: function(response) {
    var message = response.responseJSON.error;
    this.set('controller.error', message);
  },

  resetController: function(controller) {
    controller.setProperties({error: null, notice: null});
  }
});

app/login/template.hbs

...
<div class='form-group'>
  <button {{action 'login' model}} type='submit' class="btn btn-default form-control">Sign in</button>
</div>
...




Aucun commentaire:

Enregistrer un commentaire