Home path, first route and reload page


#1

Hi!

I miss something important with my landing view. For now, i only have one view

var mainView = app.views.create('.view-main');

my different routed pages are screened above it.

so i have a route for “home”

{
path: '/',
options: {
  reloadCurrent: true
},
url: route_root+'/pages/index.html',
on:{
  pageInit: function (e, page) {
    console.log(page.view);
  },
  pageReinit:function(e,page){
    console.log(page.view);
  }
}
}

but the events are never called. How can i pass data to my initial view, and how can i go back to it ? (if i put an a link towards “/” nothing happens. no event is triggered.)

and it is possible to call a template for this initial view ?


#2

if i put code into the view event, it works

var mainView = app.views.create('.view-main', {
  url: '/my/path/pages/index.html',
  on: {
    pageInit: function (e, page) {
    console.log(e, page);
  }
 }
}); 

but i don’t manage to pass variables to my html like that.

so i thought to put a resolver in my fist route :

{
 path: '/',
  alias: '/my-mobile-page/',
  options: {
    reloadCurrent: true
  },
  url: route_root+'/pages/index.html',
  async(routeTo, routeFrom, resolve, reject) {
     if (userIsLoggedIn) {
       resolve({ url: 'secured.html' })
     } else {
      resolve({ url: 'login.html' })
     }
    },
    on:{
     pageInit: function (e, page) {
      console.log(page.view);
      }
    }
  }

but nothing happens. Maybe the best is to stay in main view context, but i would like to use a template… (i have several blocks of ajax-called data to print…)


#3
  1. don’t use reloadCurrent on home route
  2. url and async can’t be used together. Use something one

#4

I may say my path is not the root url of the domain : http://mydomain.fr/ma-ludo-mobile/
No change with my first screen (that should be, as secured.html, login.html and userIsLoggedIn don’t exist).

routes = [
{
 path: '/',
 alias: '/ma-ludo-mobile/',
 async(routeTo, routeFrom, resolve, reject) {
  if (userIsLoggedIn) {
    resolve({ url: 'secured.html' })
  } else {
    resolve({ url: 'login.html' })
  }
}
},
{
  path: '/about/',
  url: route_root+'/pages/about.html',
 }   
 ];

#5

And did you implement userIsLoggedIn? It was in example just for example assuming you have own login implementation


#6

Also when you expect your home route to be parsed by router, your view must be empty, shouldn’t contain any page element