I am having problems with the application routes, I am trying to put an action that when the user opens the application it is redirected to the Login screen.
Example my code:
var Index = {
//Application Constructor
initialize: function() {
this.bindEvents();
},
//Bind Event Listeners
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.addEventListener("resume", this.onResume, false);
},
//Event Handle
onDeviceReady: function() {
if(!localStorage.getItem('isLogged')){
alert('Inside')
app.router.navigate('/login/');
}
},
//Event Handle
onResume: function() {
}
};
$(function(){
Index.initialize();
});
The alert is displayed, but my route does not work …No error is displayed on the console. But, if on the console I put “app.router.navigate(’/login/’)” in this case the screen is redirected for o Login.
I recently tried another method that I saw, which is adding within the application instance the check, I did this way:
// Init App
var app = new Framework7({
id: 'testes.app.testes',
root: '#app',
theme: theme,
data: function () {
return {
//url: 'http://127.0.0.1:8000/',
name: '',
};
},
dialog: {
title: 'Alerta',
buttonOk: 'Sim',
buttonCancel: 'Não',
},
methods: {
error: function (http) {
if(http.response != '' && http.response.indexOf('message') > 0){
var json = JSON.parse(http.response);
app.dialog.alert(json.message);
}else{
app.dialog.alert('Ops, ocorreu algum problema para realizar a conexão, tente novamente em instantes.');
}
},
},
on: {
pageInit: function() {
if(!localStorage.getItem('isLogged')){
this.router.navigate('/login/');
}
}
},
routes: routes,
});
But not work… Any solution???