[SOLVED] Page.context undefined


#1

Hi,

I’m trying to get back my data passed in context. on documentation it’s indicated there’s a page.context variable, but i’ve got undefined instead. Is it because i’m using a component ?

'stats': {
path: '/plays/stats/',
async(routeTo, routeFrom, resolve, reject) {
  var router = this;
  var app = router.app;
  app.preloader.show();
  app.request.json(THEMEREX_ajax_url, { controler: 'StatsPartie', action: 'getStatsByUser', auteur: userId, userId: userId }, function (data) {
    app.preloader.hide();
    // console.log(data.return, routeTo);  
    resolve({ componentUrl: route_root + '/pages/plays/stats.html' }, { context: { stats: data.return } });
  });
},
on: { 
  pageInit: function (e, page) {
    var pageContainer = page.$pageEl;
    console.log(page.view, page.context);        
  }
}  

}


#2

Are you on latest 2.0.10 version?


#3

no, 2.0.1. Have i to update ?


#4
page.route.context

always better to update


#5

Update done.

Thanks for your answer, plpl !

but the result is undefined… :’(

'stats': {
path: '/plays/stats/',
async(routeTo, routeFrom, resolve, reject) {
  var router = this;
  var app = router.app;
  app.preloader.show();
  app.request.json(THEMEREX_ajax_url, { controler: 'StatsPartie', action: 'getStatsByUser', auteur: userId, userId: userId }, function (data) {
    app.preloader.hide();
    // console.log(data.return, routeTo);  
    resolve({ componentUrl: route_root + '/pages/plays/stats.html' }, { context: { stats: data.return } });
  });
},
on: { 
  pageInit: function (e, page) {
    var pageContainer = page.$pageEl;
    console.log(page.route.context);        
  }
}  
}

#6
// kitchen-sink
{
  path: '/action-sheet/',
  options: {
    context:{/*keep it empty*/}
  },
  /*componentUrl:'./pages/action-sheet.html',*/
  async:function(routeTo,routeFrom,resolve,reject){
    resolve({componentUrl:'./pages/action-sheet.html'},{context:{foo:'bar'}});
  },
  on:{ 
    pageInit:function(page){        
      console.log(page.detail.route.context.foo); // => 'bar'     
    }
  } 
}
// your case
{
  path:'/stats/',
  options: {
    context:{/*keep it empty*/} 
  },
  /*componentUrl:'/path/to/stats.html'*/
  async(routeTo,routeFrom,resolve,reject){
    resolve({componentUrl:'/path/to/stats.html'},{context:{stats:'ok'}});
  },
  on:{ 
    pageInit:function(page){
      console.log(page.detail.route.context.stats); // => 'ok'       
    }
  }  
}

#7

It was

console.log(e.detail.route.context.stats);

for me,very thanks, the addition of empty options.context was mandatory, i didn’t know that.


#8
{
  on: { 
    pageInit:function(e,ee,page){        
      console.log(e.detail.route.context.stats);   // => 'ok'
      console.log(ee.detail.route.context.stats);  // => 'ok'
      console.log(page.route.context.stats);       // => 'ok'
    }
  } 
} 

#9

my mistake :slight_smile:
Thanks again.