Check username every time on page init

$$(document).on('page:init', function (e) {
  if (auth.username == null) {
    mainView.router.load({
      url: './pages/login.html',
      ignoreCache: true
    });
//    alert(auth.u_id);
  }
});

It work at the 1st load only but I would like to make it check every time then redirect to login page.

Use page before in event

page:beforein
Page Element

Event will be triggered when everything initialized and page is ready to be transitioned into view (into active/current position)

https://framework7.io/docs/routes.html#async-route

What is it, v1? In v1 it is not really possible. In v5 there is a async routes or route’s beforeEnter hook designed for this