Kadzhaev Marat
Kadzhaev Marat

Reputation: 1317

Spring MVC, Thymeleaf URL

I have settings page and controller for him:

@RequestMapping(value = "/settings/password/change", method = RequestMethod.GET)
public String changePassword(Model model) {
    return "account/changepassword";
}

On this page there is header which contains link on myaccount: <a class="link" th:href="${currentUser.nickname}"><li class="li">User profile</li></a> But if I open settings page link on header have URL: localhost:8080/settings/password/change/profilename. Instead of this I need URL like: localhost:8080/profilename. How I can do it?

Upvotes: 2

Views: 488

Answers (1)

Tob&#237;as
Tob&#237;as

Reputation: 6297

You get /settings/password/change/profilename because th:href="${currentUser.nickname}" creates a relative URL to the current path: <a href="profilename"/>

Instead, try using this Thymeleaf syntax in order to build a context-relative URL:

<a th:href="@{/{profilename}(profilename=${currentUser.nickname})}">link</a>

Upvotes: 2

Related Questions