如何在SPA禁用默认页面JQM? [英] How to disable the default JQM page in a SPA?

查看:132
本文介绍了如何在SPA禁用默认页面JQM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单页JQM应用程序 - 所有JQM页面是一个文档中:

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>

如何禁用显示在默认情况下,目前正好是一个login.cshtml JQM页面,这样我就可以手动调用转换方法,从历史上抹去的登录页面,用户登录后? EQ这就是我想要手动调用初始文档加载:

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 });

另外,是不是可以设置反向属性设置为false没有一个 changePage 打电话?

推荐答案

如果你想我可以给你一个客户端解决方案。

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

基本上,你是用我的旧的例子: http://jsfiddle.net/Gajotres/3PhKZ/为prevent页面转换,如果没有满足一定条件。而在这一点上,你可以在与changePage功能的任何其他页面转发用户。

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.

这个解决方案将在任何情况下工作,因为它会在每一页转换过程中触发,如果下一页是你的情况的登录页面会看情况,做任何你想要的。您可以允许过渡,prevent它完全或只是重定向到另一页:

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');;
        }  
    }
});

这篇关于如何在SPA禁用默认页面JQM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆