7

こんにちは、「History」クラスを介して履歴をサポートするために、GWT とその標準的な方法を使用しています。非常に便利ですが、URLからアンカー部分を削除するにはどうすればよいですか? 例えば:

私のベースURL:

http://www.mysuperwebsite.com/myapp

アプリケーションを使用しながら、新しい履歴アイテムを追加する場所に移動します。

コード内:

History.newItem("funnygame");

結果:

http://www.mysuperwebsite.com/myapp#funnygame

私はもう一度場所を変えます:

コード内:

History.newItem("notsofunnygames");

結果:

http://www.mysuperwebsite.com/myapp#notsofunnygames

次に、ホームページ (http://www.mysuperwebsite.com/myapp) に戻りたいと思います。

コードには何を配置する必要がありますか?:

????

戻るには:

http://www.mysuperwebsite.com/myapp

目標を達成できる標準的な方法はありますか?


次のようなものを追加すると:

History.newItem(""); 

また

History.newItem(null); 

URLは次のようになります

http://www.mysuperwebsite.com/myapp#

そして、これは私が望んでいるものではありません。鋭い性格のないものが必要です。

4

4 に答える 4

5

History.newItem(null);新しいイベントを使用すると、発生します。その結果、ホームページを切り替えます: http://www.mysuperwebsite.com/myapp#

最後に # があるかどうかは同じことですが、間違っていますか?

編集:

  ...
  // Get the last part of the url and remove #token
  String s = Location.getHref().substring(Location.getHref().lastIndexOf("/"));
  s = s.substring(0, s.indexOf("#")-1);
  setToken(s);
  ...

  protected native void setToken(String token) /*-{
    $wnd.history.pushState({},'', token);
}-*/;
于 2011-01-31T14:48:34.873 に答える
2

アンカーは で識別される#ため、次を使用して削除できます。

int index = link.indexOf('#');
if (index != -1) {
    link = link.substring(0, index);
}
于 2011-01-31T10:45:33.633 に答える
0

ツール クラスを作成して、履歴が変更されたときにそれを呼び出すことができます。

public class UrlUpdater {

    public static void removeHashIfEmpty() {
        if(isHashEmpty())
            removeHash();
    }

    private static boolean isHashEmpty() {
        return "#".equals(Window.Location.getHash());
    }

    private static void removeHash() {
        updateURLWithoutReloading(Window.Location.createUrlBuilder().setHash(null).buildString());
    }

    private static native void updateURLWithoutReloading(String newUrl) /*-{
        $wnd.history.replaceState({}, null, newUrl);
    }-*/;

}
于 2016-06-21T21:31:51.760 に答える
0

If you dont want a historytoken you are probably using history wrong. If you're not intending to fiddle with navigation i would recommend using GwtEvent / EventHandler. Which is essentially what gwt's History class does, in addition to linking those events to the navigation history.

于 2011-02-01T13:15:42.597 に答える