0

I have 3 views in my router. The index view picks viewtwo as the default.

The problem is when I go to viewone or viewthree it goes through the index route! and loads the viewto before then rerouting to whichever I clicked viewone or viewthree and in my setup that causes some glitch as each view does something to the HTML that it then has to undo before leaving but something is not syncing too well (I tested it has something to do with how fast things load and javascript is applied onto it because my glitch only occurs if I click back and forth really fast).

What is the opposite of didInsertElement right before it gets destroyed?

Also why is the viewto getting loaded from the index route?

index: Ember.Route.extend({
    route: '/',
    redirectsTo: 'viewtwo'
}),

viewone: Ember.Route.extend({
    route: '/viewone',
connectOutlets: function( router ) {
....

viewtwo: Ember.Route.extend({
    route: '/viewtwo',
connectOutlets: function( router ) {
....    

viewthree: Ember.Route.extend({
    route: '/viewthree/:item_id',
connectOutlets: function( router, item ) {
....    
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
user391986
  • 29,536
  • 39
  • 126
  • 205

1 Answers1

1

What is the opposite of didInsertElement right before it gets destroyed?

willDestroyElement. See this page: http://emberjs.com/api/classes/Ember.View.html#event_willDestroyElement

Also why is the viewto getting loaded from the index route?

The reason index loads viewto is because of the redirect, but I think you already knew that. Not sure what you are asking here.

As far as all your routes going through index, you might want to post a fiddle that emulates this problem. /viewthree should not enter index from what you've posted. If you post a fiddle that can reproduce the problem it will help people provide better answers.

Ryan
  • 3,594
  • 1
  • 24
  • 23
  • 1
    Essentially, when the router figures out which route it should navigate to, it creates a path like `root.viewthree`. It then enters each state in turn, setting each state up as if no other states follow it. This means it enters the root state, sees the redirectTo, and redirects. This means the current path is now `root.viewtwo` (incorrectly). It then runs the enter state for viewtwo (which it thinks is correct). It then backs up to what is actually correct (viewthree) and runs the enter state for that (which changes the current path from `root.viewtwo` back to `root.viewthree`. – bengillies Nov 19 '12 at 18:01