我可以在没有提交的情况下更改网址(设置参数)吗?我找到了这个方法 http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/client/Window.Location.html#replace%28java.lang.String%29 但是它提交页面.所有GWT状态都将丢失.
111*_*01b 10
如果您想要更改散列中没有的内容,例如您想要更改URL中的参数,您可以这样做!
private void someMethod() {
String newURL = Window.Location.createUrlBuilder().setParameter("someParam", "someValue").buildString();
updateURLWithoutReloading(newURL);
}
private static native void updateURLWithoutReloading(String newUrl) /*-{
$wnd.history.pushState(newUrl, "", newUrl);
}-*/;
Run Code Online (Sandbox Code Playgroud)
然后,你可以注册一个处理使用前进和后退按钮浏览器作为展示用户的功能在这里.
你为什么要这样做?一般来说,GWT应用程序不会更改页面 - 因此它们通常是SPA(单页面应用程序)
从服务器加载新页面时,您将丢失该页面上的状态.您可以更改URL的哈希部分,因为它不会返回到服务器,如下所示:
String newURL = Window.Location.createUrlBuilder().setHash("newhash").buildString();
Window.Location.replace(newURL);
Run Code Online (Sandbox Code Playgroud)
但是,如果您要这样做,我建议您查看GWT的MVP框架,该框架内置支持使用散列令牌管理位置.
http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html
| 归档时间: |
|
| 查看次数: |
5372 次 |
| 最近记录: |