[SOLVED] Android mainView.router.navigate is not working

Hi

I’m trying to navigate through views using routes. When I test in browser(chrome mobile view) it works fine, but when I make build using cordova and test in android its not working. Surprisingly it works fine in iPhone too, it got me confused more.

On document load I’m trying to direct to another route but its not working in android alone. it stucks at ‘/’ landing view itself. Below is my code.

My main view initialization

var mainView = app.views.create('#view-home', {
    url: '/',
    name: 'main'
});

Navigation to view

$$(document).on('DOMContentLoaded', function () {
    mainView.router.navigate('/home/emp/');
});

Please help me to solve this.
Thanks in advance.

Hi!

If you using cordova, try this.

   /* This call onDeviceReady when the device is ready*/
    document.addEventListener('deviceready', core.onDeviceReady, false);
    var core = {
        onDeviceReady: function() {
        	/* Change "app" variable for you Framework7 object new Framework7(....)*/
            app.router.navigate('/home/emp/');
            /* /home/emp/ should exist in routes params in Framework7() */
        }
    };

Regards!

1 Like

Thanks :+1:, this seems to be valid solution.

By the way I tried this, this also worked.

$$(document).on(‘DOMContentLoaded’, function () {
setTimeout(function () {
fnIndexInit();
}, 500);
});

1 Like

Yes Great!

For cordova applications is recomended using deviceready, is triggered is when all is loaded.

Cordova Doc
“This event is essential to any application. It signals that Cordova’s device APIs have loaded and are ready to access.”

https://cordova.apache.org/docs/en/latest/cordova/events/events.html#deviceready

then, that’s how you make sure that everything is ready

Regards!

1 Like