1. Problem
We want to build a link that starts with a context path in Thymeleaf view. Additionally, we want to create this link in JavaScript.
2. Solution
To create a Context-relative URLs we need to use @
in th:href
attribute like in the following example:
if application was installed under http://localhost:8080/sampleapp
that URL will look like the following:
Read more about how to create links in Thymeleaf here.
In case you need to define an URL in JavaScript code:
The /*[[ - ]]*/
syntax is used by Thymeleaf to evaluate variables used in JavaScript.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}