gwt 多页应用程序 [英] gwt multi-page application
问题描述
我有一个多页应用程序,需要手动从一个页面切换到另一个页面.它可以在 GWT 中完成,因为它是针对单页应用程序的.我正在从 Google 代码和在线论坛中学习,但找不到任何具有未通过公共入口点链接的多页面的应用程序.有什么想法吗?
I have a multipage application which needs to manually switched from one page to another. could it be done in GWT since it is targeted towards single page application. I am learning from the Google code and online forums but could not find any application which had multi-pages not linked by a common entry-point. Any ideas?
推荐答案
GWT 通过 URL 片段标识符 (FI),即 http://www.yourhost.vom/main#pagename
,其中pagename"是表示您的页面"的片段标识符应用程序.
GWT has support for "pages" within application via URL fragment identifier (FI), i.e. http://www.yourhost.vom/main#pagename
, where "pagename" is a fragment identifier representing a "page" within your app.
这个页面"(请注意,浏览器从不真正重新加载页面,因此 GWT 应用程序保持不变),具有完整的历史支持并且可以添加书签.
This "pages" (note that browser never really reloads the page, so GWT app stays the same), have full history support and are bookmarkable.
注意:在整个 GWT 文档中,片段标识符有时被称为地点标记或历史标记.
NOTE: throughout GWT docs fragment identifier is sometimes referred to as place token or history token.
通过将 iframe 添加到您的主机页面:
Enable history support by adding an iframe to your host page:
<iframe src="javascript:''"
id="__gwt_historyFrame"
style="width:0;height:0;border:0">
</iframe>
注册一个 ValueChangeHandler 以在 FI(页面)更改时收到通知:History.addValueChangeHandler(..)
.在此处理程序中,您放置了一个显示新页面的逻辑.
Register a ValueChangeHandler to be notified when FI (page) changes: History.addValueChangeHandler(..)
. Within this handler you put a logic that displays the new page.
通过调用History.newItem("newpage")
(不带#)进入特定页面
Go to a particular page by calling History.newItem("newpage")
(without #)
您甚至可以将参数"传递给页面,方法是将片段标识符分成子部分:例如#edit/user4".只需解析此 FI,调用显示编辑页面的代码并将user4"传递给它.您可以使用任何字符将 FI 分为页面"部分和参数"部分(我在这里使用/").要在现实生活中看到这一点:在 Gmail 中打开一封邮件并查看 URL.
You can even pass "parameters" to page, by dividing fragment identifier into sub parts: for example "#edit/user4". Just parse this FI, invoke code that shows edit page and pass "user4" to it. You can use any character to divide FI into a "page" part and "parameter" part (I use "/" here). To see this in real life: open a message in gmail and look at URL.
这篇关于gwt 多页应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!