BeforeEnterEvent.forwardToUrl(String) should forward to the given URL
See original GitHub issueDescription of the bug / feature
With this before enter event handler
@Route(value = "hello")
public class HelloWorldView extends HorizontalLayout implements BeforeEnterObserver {
@Override
public void beforeEnter(BeforeEnterEvent event) {
event.forwardTo("/hello/world/");
}
and a servlet deployed using context path /context
You would expect that opening /context/hello
would redirect to /hello/world/
. Instead it redirects to /context/hello/world
.
The URL is wrong (relative to /context
) and the trailing slash is missing.
Minimal reproducible example
git clone https://github.com/Artur-/test-forward-to-url
cd test-forward-to-url
open http://localhost:8080/context/hello
Expected behavior
http://localhost:8080/hello/world/ is shown
Actual behavior
http://localhost:8080/context/hello/world is shown
Versions:
- Vaadin / Flow version: 19
- Java version: 15
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Class BeforeEvent - Vaadin
Gets the forward target handler to use if the user should be forwarded to some other view. List<String>, getForwardTargetParameters(). Get the URL parameters...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Based on the code and commits I would interpret it as
forwardTo
is for navigating to either a server (Flow) or client side (Fusion) view. In that case (and to prevent breaking compatibility) aforwardToUrl
would make more sense.The use case here is to be able to prevent navigation to a given view and redirect to a (maybe external) login view instead.
Maybe I’m missing something - but it looks to me that the existing
forwardTo
API inBeforeEvent
is eitherNavigationState
which I think should not be even visible for users (?)Now it should instead redirect to an URL outside the application ? Why not add
forwardToUrl(String url)
instead ? Basically like requested in https://github.com/vaadin/flow/issues/4606 but sinceredirectTo
is not intended to update the URL, it should not beredirectTo
butforwardTo
instead. I don’t think it is possible to redirect without changing the url so the other issue is kind of invalid in that regard.