question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BeforeEnterEvent.forwardToUrl(String) should forward to the given URL

See original GitHub issue

Description 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:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Artur-commented, May 19, 2021

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) a forwardToUrl 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.

1reaction
plekucommented, May 19, 2021

Maybe I’m missing something - but it looks to me that the existing forwardTo API in BeforeEvent is either

  • for Flow based routes or paths to the routes
  • for NavigationState 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 since redirectTo is not intended to update the URL, it should not be redirectTo but forwardTo 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found