Router navigate to page from root in v4

Hello,

I am trying to navigate to a specific page from root of my script.

var app = new Framework7({
    root: '#app',
    routes: [{
        path: '/',
        url: './index.html',
    }]
    // here in some page I run **something()** function
});
var mainView = app.views.create('.view-main', {
    url: '/',
    pushState: true,
});
function something(){
    $.ajax({
        url: url,
        success: function() {
            app.router.navigate('/products/');
            app.views.main.router.navigate('/products/');
            self.app.router.navigate('/products/', {reloadCurrent: true});
            // tried with all of this, none works
            // this works but inside of routes - page.router.navigate('/link/');
        }
    });
}

returns this error Framework7: it is not allowed to use router methods on global app router. Use router methods only on related View, e.g. app.views.main.router.navigate(…) or Cannot read property ‘router’ of undefined

I just updated from v2 to latest version 4.4.7

app.views.main.router.navigate(’/products/’);

1 Like

Tried that too > Uncaught TypeError: Cannot read property ‘router’ of undefined

Значит у вас нет main view

I have it as you can see in my script.
changed html to this too, same - dunno if has something to do with this.

<div class="view view-init safe-areas" data-push-state="true" data-url="/">

view view-init safe-areas => view view-main view-init safe-areas

1 Like

Thanks, this was missing. I guess when I have added view-init, removed it from mistake