How to use in-page HTML anchors with hashbang URLs (in GWT)?
-
21-06-2021 - |
Pregunta
I have a little problem with implementing in-page HTML anchors while also having bookmarkable URLs via hashbang. The description is easy:
- I visit some URL of my application: http://www.mypage.com/Test.html#!mycontent
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>
.
- But when I click this link in my GWT application, the URL changes to: http://www.mypage.com/Test.html#myAnchor
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?
Solución
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>