BeforeEvent.rerouteTo not replacing browser URI

Hi,
I have a view with expected parameters and in case those parameters are not correct I would like that this view gets loaded with its default setup.
e.g. when users types into URL /page/wrong-segment and wrong-segment is not recognizable by the view itself I would like that /page/default-segment is visible (as well in the browser bar).
BeforeEvent.rerouteTo reexecutes setParameter() method, however uri address in the browser bar stays wrong. Am I doing something wrong?
Thnx for any hint
Martin

I’ve seen the same behavior and use something similar to the following method to update the browser url and back button history.

	public static void updateBrowserUrl(Class<? extends Component> c) {
		Assert.notNull(c, "c is a required argument.");
		UI ui = UI.getCurrent();
		String url = ui.getRouter().getUrl(c);
		ui.getPage().getHistory().pushState(null, new Location(url));
	}

Thanks jackster for this hint.
At what time did you apply it exactly? Just before there is call to BeforeEvent.rerouteTo executed?

So I found, that this is a reported bug (https://github.com/vaadin/flow/issues/4189) and it has been fixed (resp. enhanced). Using of rerouteTo() is misusing the method and new forwardTo() method should be used instead.
This has been added in vaadin-flow v1.3.0. Unfortunately latest v12 Vaadin version is still on 1.2.5 version of flow. Simple update of flow-server to v1.3+ is not working as there seems to be some breaking changes between 1.2 & 1.3, so we need to wait until it propagates into some main vaadin version.

I call the method after the event.rerouteTo call.

Good find on issue 4189.

Well, not sure about other cases, but for this particular case even forwardTo doesn’t change URL. As well it doesn’t do rerouting at all. rerouteTo at least does the rerouting…

Im calling this manually:

    UI.getCurrent().page.history.replaceState(null, [parameter]

)

Why are you not using forwardTo(View.class)? That should do the job

That wasn’t the option at the time of the issue Andre :). Today, the issue is obsolete.