Rui*_*ira 6 browser html5 browser-history dart
是否有任何设施可以帮助处理Dart标准库中的状态和后退按钮?或者我是否需要模拟Javascript解决方案来实现Web应用程序状态的导航?
我打算将其应用于个人项目,因此浏览器兼容性不是问题(即仅HTML5解决方案就可以了).
非常感谢.
HTML5定义了用于操作历史记录的新API,允许您在不重新加载窗口的情况下更改位置.有一篇关于Dive Into HTML5的精彩文章,展示了如何使用历史API在单页面应用中模拟多页面导航.它很容易翻译成Dart.
这是文章:http: //diveintohtml5.info/history.html
以下是历史的Dart文档:http: //api.dartlang.org/docs/continuous/dart_html/History.html
在带导航的单页应用程序中,我通常设置客户端代码的方式类似于在服务器上设置RoR或Django应用程序或Dart http服务器的方式:
然后使其成为无缝体验:
样品:
main() {
// handle the back button
window.on.popState.add((_) => showPage());
}
showPage() {
String path = window.location.pathname;
if (path == '/') {
showFrontPage();
} else if (DETAIL_PAGE_URL.hasMatch(path)) {
String id = DETAIL_PAGE_URL.firstMatch(path).group(1);
showDetailPage(i);
}
}
showFrontPage() {
//... code to build a link to a detail page
detailAnchor.on.click.add((MouseEvent e) {
window.history.pushState(null, detail.title, detail.url);
e.preventDefault();
showDetailPage(detail);
}, false);
}
Run Code Online (Sandbox Code Playgroud)