How to redirect in Framework7

I’m using Framework7 (3.5) for a while and every time I get crazy because of documentation.

I need to do a simple redirect if the user is logged in. The user informations are stored on Local Storage. So I perform this on pageInit function of my page:

user= window.localStorage.getItem("user")


if(user == null){
    console.log("User doesn't exist")
    app.router.navigate('/login/', {reloadAll: true});
}
else{
    console.log("User exist")
    app.router.navigate('/home/', {reloadAll: true});
}

So the log messages work fine, but the app.router.navigate are totaly ignored by the framework. The routes are create in the right way on myApp.js (already tested) and the app.router.navigate works only if I use Dom7('#random-button').on('click, function(){}).

If I trigger the onClick function the redirect works, without no.

Any idea why?

https://framework7.io/docs/routes.html#async-route тут есть пример как делать redirect в зависимости от того гость или нет

It depends on where and before/after you call that code. And there is no app.router, router methods should be used on relevant View like app.views.main.router.navigate(...)

if(user == null){
    console.log("User doesn't exist")
    app.views.main.router.navigate(...)
}
else{
    console.log("User exist")
   app.views.main.router.navigate(...)
}

Shold be ok?

Should be, but still depends on where do you call it