¿Cómo creo la página de inicio para el recurso sobre 'philosophy.hbs' en lugar de 'index.hbs' y sigo manteniendo la clase 'activa' de Ember?

My ember router looks like this:

Ew.Router.map ->
  @.resource "about", ->
    @.route "philosophy"
    @.route "leadership"
    @.route "staff"
    @.route "affiliations"
  @.route "conditions"
  @.route "programs"
  @.route "testimonials"

In application.hbs I have a nav bar and when you click 'ABOUT' a subnav displays with subpage links. I would like 'ABOUT' to link to 'philosophy.hbs' instead of 'about/index.hbs'. However, when I do this the 'active' class shows up on 'ABOUT' on the main nav, and 'PHILOSOPHY' on the subnav, which is correct. However, as soon as I click on another subpage of about, the 'active' class on 'ABOUT' disappears and only displays on the subnav link.

The only way I can get the 'active' class to always display on the main nav 'ABOUT' is to have an 'about/index.hbs' page. But due to the architecture of the site i really need 'philosophy.hbs' to be the main about landing page and not 'index'

Any ideas why this is breaking the 'active' state, even though the url still reads '/about/leadership', '/about/staff', etc? I would think as long as /about is in the url the active state on that link should be active.

preguntado el 09 de septiembre de 13 a las 22:09

2 Respuestas

I think you need to add a redirect to the about route which will display the philosophy.hbs

App.AboutRoute = Ember.Route.extend({
  redirect: function(){
    this.transitionTo('about.philosophy');
  }
});

I have a create a jsbin let me know if that works.

¡Salud

Respondido el 09 de Septiembre de 13 a las 23:09

This worked. Thank you very much. Anyway you can explain to me why it is necessary to do this? - rechinar

Have you tried specifying the path on your route?

App.Router.map(function() {


this.resource('philosophy', { path: '/about' },  function() {
    this.route('leadership');
    // other routes
  });
});

Does this JSBin capture what you are trying to do? http://jsbin.com/UYIraQO/1/edit

Respondido el 09 de Septiembre de 13 a las 23:09

I did, however the resource is 'about', not philosophy. Philosophy and leadership are subpages of About. - rechinar

The URLs should still work as expected if I understand what you want correctly. I've updated the JSBin to include an index for Philosophy: jsbin.com/UYIraQO/2/edit si eso ayuda. - Lanza Harper

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.