I need create a url in thymeleaf with anchor. Like:
/import#34546
But the link url expression does not work.
<a th:href="@{import#{id}(id=${object.id}}">link</a>
someone get this url using thymeleaf?
I use thymeleaf with spring-boot 2.5.4.
Thanks!
@{...}
syntax supports URL fragments (meaning a#
followed by a fragment identifier). It only supports path segments and query parameters. Therefore the only way I know to achieve this is with a string expression, for example<a th:href="${'import#' + object.id}">link</a>
or any equivalent string variation. Leaving this as a comment in case someone proves me wrong. – andrewjames)
in...(id=${object.id})}
- but that still does not evaluate to what you need. – andrewjames<a th:href="@{import} + ${'#' + object_id}">link</a>
. This still relies on string concatenation, but you also are still using@{...}
and can therefore still take advantage of its features (such as handling for absolute and relative URLs). – andrewjames