gwt 多页面应用程序
我有一个多页面应用程序,需要手动从一个页面切换到另一页面。它可以在 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GWT 通过 URL 片段标识符 (FI) 支持应用程序内的“页面”,即
http://www.yourhost.vom/main#pagename
,其中“pagename”是代表应用内“页面”的片段标识符。该“页面”(请注意,浏览器永远不会真正重新加载页面,因此 GWT 应用程序保持不变)具有完整的历史记录支持并且可添加书签。
注意:在整个 GWT 文档中,片段标识符有时称为位置标记或历史标记。
通过向您的主页添加 iframe 来启用历史记录支持:
注册一个 ValueChangeHandler,以便在 FI(页面)更改时收到通知:
History.addValueChangeHandler(..)
。在此处理程序中,您放置一个显示新页面的逻辑。通过调用
History.newItem("newpage") 转到特定页面
(不带 #)您甚至可以通过将片段标识符划分为子部分来将“参数”传递给页面:例如“#edit/user4”。只需解析此 FI,调用显示编辑页面的代码并将“user4”传递给它即可。你可以使用任何字符将FI分为“页面”部分和“参数”部分(我这里使用“/”)。要在现实生活中看到这一点:在 gmail 中打开一条消息并查看 URL。
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.This "pages" (note that browser never really reloads the page, so GWT app stays the same), have full history support and are bookmarkable.
NOTE: throughout GWT docs fragment identifier is sometimes referred to as place token or history token.
Enable history support by adding an iframe to your host page:
Register a ValueChangeHandler to be notified when FI (page) changes:
History.addValueChangeHandler(..)
. Within this handler you put a logic that displays the new page.Go to a particular page by calling
History.newItem("newpage")
(without #)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 来切换页面,但生成的代码会很慢且不是最佳的,页面加载时间会更长。
While you can use GWT to switch pages, the resulting code will be slow and suboptimal, with the pages taking longer to load.