This is your kitchen sink demo for 2.0.10. The only thing I changed was the code above in app.js. We already established we can’t use app.views.create on a view that has been initialized previously because it throws this error:
It doesn’t navigate to the buttons page. Any ideas?
EDIT: It only works when I set pushState to false. I need pushState to so I can navigate directly to the url during testing. I have tried setting it in both app and view and neither works.
Can you post an example of using init: false, with pushState: true, and navigate to a page on init? I am unable to migrate my app from v1 until this is working.
In v1 I simply did:
myApp.init();
mainView = myApp.addView('.view-main', {
});
if (updatesPending){
var t = mainView.router.loadPage({url: 'templates/update.html'});
} else {
var t = mainView.router.loadPage({url: 'templates/login.html'});
}
var userIsLoggedIn = true;
var updatesPending = false;
var routeState=document.location.hash.split('#!')[1];
var state={
name:'state',
url:document.location.href.split('#!')[0]
};
history.pushState(state,state.name,state.url);
var app=new Framework7({
root:'#app',
init:false,
routes:[
{// by logic the url "with this route"
// should be https://www.mysite.com/index.html "anyway"
path: '/',
async(routeTo,routeFrom,resolve,reject){
resolve({
url:userIsLoggedIn ?
updatesPending ?
'./templates/page-updates.html' : // the url is .../index.html
'./templates/page-home.html' : // the url is .../index.html
'./templates/page-login.html' // the url is .../index.html
},{
once:userIsLoggedIn ?
updatesPending ?
{ } :
{// fire once.
// and only if userIsLoggedIn:true and updatesPending:false
pageMounted:function(e,page) {
page.view.router.params.pushState=true;
if(routeState){//if the url has "hash" (route.path)
setTimeout(function(){
page.view.router.navigate(routeState,{animate:false});
// the url is .../index.html#! + (/workorder/ || /photos/)
},0);
}
}
} :
{ }
});
}
},
{// the url will be https://www.mysite.com/index.html#!/workorder/
path:'/workorder/',
url:'./templates/page-workorder.html'
},
{// the url will be https://www.mysite.com/index.html#!/photos/
path:'/photos/',
url:'./templates/page-photos.html'
}
]
});
var view=app.views.create('.view-main',{
url:'/'
});
app.init();