gwtanchorgwt-platformhashbanggwt-places

How to use in-page HTML anchors with hashbang URLs (in GWT)?


I have a little problem with implementing in-page HTML anchors while also having bookmarkable URLs via hashbang. The description is easy:

On this page there is a lot of text and I need some HTML anchors for navigation. In old-style HTML I'd write <a href="#myAnchor">AnchorText</a>.

GWT Platform recognized the change and throws me back to my DefaultPlace. That's clear because it can't associate the URL to a presenter.

So now the (simple) question is: How can I use in-page navigation while also having hashbang URLs?


Solution

  • How do you construct your anchor?
    In case you are doing it statically, why now just add the ! to the href?:
    <a href="!#myAnchor">AnchorText</a>

    Update: Ok Instead of an normal Anchor you can use a Hyperlink or InlineHyperlink and set the targetHistoryToken value to #!myAnchor:

    <g:InlineHyperlink ui:field="diversityLink" targetHistoryToken="!#myAnchor">MyAnchor</g:InlineHyperlink>