Framework7: router.loadPage doesn't work

Created on 29 Sep 2015  Â·  6Comments  Â·  Source: framework7io/framework7

We listen onPageBeforeInit (tried onPageInit as well, didn't help). The listener calls our init script. This script checks authorization and if the current user is not authed then calls mainView.router.loadPage('login.html'). The login page has a button to get back which loads previouse page (with auth checking). It again checks authorization, gets on line with loadPage(…) and nothing happens, it just goes throught it and ‘login.html’ is not opened. So loadPage doesn't work on the second attempt.
We have played with this bug and found out that it works if loadPage(…) is inside of setTimeout with 400ms delay (less doesn't work).
So it looks like framework7 does something inside, like initialization or kind of and it take ~400ms and it blocks loadPage(..) method.

outdated

Most helpful comment

Is there any other way other than preroute to handle this ? I am stuck at this point and it is not working at ll.

All 6 comments

I have had this issue before. Its not broken, just doesn't work as expected. A page is initiated once if its still in the history, doesn't initiate twice.

@MarcGodard how did you handle it? i mean it's not good at all to call loadPage(..) from setTimeout kind of setTimeout(function(){ mainView.router.loadPage('...');}, 400);

Figured it out. You are right, it's not a bug but very expected behaviour. F7 router sets allowPageChange to false when processing its internal businesses. It blocks loadPage execution. It's possible to manualy set this var before loadPage but it breaks everything up.

allowPageChange is changed back when animation is completed (and i suppose somewhere else if animation is disabled). So animation takes ~300ms and it's the answer why 400ms timeout delay has worked out.

So, it can be handled if listen onPageAfterAnimation instead of onPageInit — our code runs after allowPageChange changed back.

But onPageAfterAnimation doesn't work out if a page has no animation. E.g. the first page works without animation and onPageAfterAnimation is not triggered.

So for correct handling this crazy stuff you need to listen both onPageAfterAnimation and onPageInit and make some logic to handle it

Right there is a lock which doesn't allow to load new page during animation in same View. As a solution you may also try to use App's preroute parameter http://www.idangero.us/framework7/docs/init-app.html#example-with-preroute

Is there any other way other than preroute to handle this ? I am stuck at this point and it is not working at ll.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mesutgok picture mesutgok  Â·  4Comments

ahmeddaif1 picture ahmeddaif1  Â·  4Comments

wakiem picture wakiem  Â·  4Comments

M4ttscx picture M4ttscx  Â·  4Comments

J05HI picture J05HI  Â·  3Comments