Reputation: 57
I would like to reuse a View implementation and define multiple, parametrized, routes to it.
Is this actually even possible? I have tried the below but always hit Error 404. It's the RouteParameters
that appear to be causing this.
Nav nav = new Nav();
RouterLink link1 = new RouterLink();
link1.setRoute(viewClass, new RouteParameters("entity", "e1"));
nav.add(link1);
RouterLink link2 = new RouterLink();
link2.setRoute(viewClass, new RouteParameters("entity", "e2"));
nav.add(link2);
Important: I do not want to show the route parameters in the URL.
Upvotes: 0
Views: 363
Reputation: 448
If you don't want to show the data in the URL, then you should be looking for other solutions than putting the values in route parameters.
If I understand you correctly, this sounds like a state management problem. There are many mechanisms for sharing state between views (including things like cookies and client-side storage), but since this is not information you want to share with the client you should be considering server-side state management options.
You aren't limited to Vaadin-specific solutions, but it does provide a few options. You can use the VaadinSession, although that will be shared between multiple browser windows so you could experience unexpected behavior if users have multiple windows open. If you're using Spring, you could define and inject a @UIScope bean and store your state there. Because a new UI is created for every browser window, the state would be isolated. If you go down this path, be careful about injecting narrowly scoped beans into more broadly scoped beans.
Upvotes: 3