简体   繁体   中英

How to disable the default JQM page in a SPA?

I have a single page JQM application - all JQM "pages" are in one document:

    <div>
        @RenderPage("Views/login.cshtml")
        @RenderPage("Views/page1.cshtml")
        @RenderPage("Views/page2.cshtml")
    </div>

How can i disable displaying a JQM page by default, which currently happens to be the login.cshtml, so i can manually invoke the transition method to erase the login page from the history, after the user has logged in ? Eq this is what i want to invoke manually on initial document load:

$.mobile.changePage('#login-page', { reverse: false, changeHash: true });

Alternatively, is it possible to set the "reverse" attribute to false without a changePage call?

If you want I can give you a client side solution.

Basically you an use my older example: http://jsfiddle.net/Gajotres/3PhKZ/ to prevent page transition if some condition is not fulfilled. And at that point you can forward that user at any other page with changePage function.

This solution will work in any case because it will trigger during every page transition and if next page is in your case login page it will look at conditions and do whatever you want. You can allow that transition, prevent it altogether or simply redirect to an another page:

$(document).on('pagebeforechange', function(e, data){  
    var to = data.toPage,
        from = data.options.fromPage;

    if (typeof to  === 'string') {
        var u = $.mobile.path.parseUrl(to);
        to = u.hash || '#' + u.pathname.substring(1);
        if (from) from = '#' + from.attr('id');

        if (from === '#index' && to === '#second') {
            alert('Can not transition from #index to #second!');
            e.preventDefault();
            e.stopPropagation();

            // remove active status on a button, if transition was triggered with a button
            $.mobile.activePage.find('.ui-btn-active').removeClass('ui-btn-active ui-focus ui-btn');;
        }  
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM