我在 Jquery Mobile 中使用嵌套页面:
看起来像这样:
// wrap page
<div data-role="page" id="wrap">
// panel
<div data-role="panel" data-id="popover">
// nested pages
<div data-role="page" id="nested1"></div>
<div data-role="page" id="nested2"></div>
</div>
</div>
在转换时,我正在切换$.mobile.pageContainers以将嵌套页面加载到面板中,而不是加载到正文中(默认 JQM),如下所示:
$.mobile.changePage( page-to-be-loaded, {
// previous page in panel
fromPage:from,
// update the URL with the nested page hash
changeHash:hashChange,
// target panel
pageContainer: $('div:jqmData(id="popover")')
});
这一切都按预期工作=当我在面板中加载嵌套页面时,URL更新为
http://some.com#nested1/2/3...
我的问题在于“清理” URL,当我离开包装页面并完全进入新的 JQM 页面时
在这种情况下,URL 停留在最后一个嵌套页面,当我需要告诉 JQM 我实际上仍在包装页面上时(无论嵌套页面仍在 URL 中)。
问题: 所以我正在寻找一种将 URL 更新为正确值的方法,或者是一种将页面参数设置为“出厂默认值”的好方法,因此 JQM 永远不会知道我在嵌套页面上做了任何面板转换。
我努力了:
// 1. location hash - doesn't work
window.location.hash = ""
// 2. ReplaceState - breaks on non-push-state browsers
// on pageinit store defaults
var $myState = {};
$myState.title = document.title;
$myState.url = location.protocol + '//' + location.host + location.pathname;
page.data("rememberState", $myState )
// before leaving the wrap page
var rem = $('#wrap.ui-page-active').data("rememberState");
if (rem && typeof rem != 'undefined') {
history.replaceState('null',rem.title,rem.url);
}
// 3. Reload the page when hiding the panel - crashes my browser :-)
$.mobile.changePage('#wrap', {
allowSamePageTransition: true,
changeHash:true,
transition:none
});
由于我远离 JQM 路径,我只是在寻找提示。感谢您的任何指示!