I have three level of layout in my route, here with this simplefied example :
@Route(value = "products", layout = SalesTemplate.class)
public class ProductTemplate extends PolymerTemplate<TemplateModel> {
// Implementation omitted
}
@Route(value = "services", layout = SalesTemplate.class)
public class ServiceTemplate extends PolymerTemplate<TemplateModel> {
// Implementation omitted
}
@ParentLayout(MainView.class)
@RoutePrefix("sales")
@Route(value = "", layout = MainView.class)
public class SalesTemplate extends PolymerTemplate<TemplateModel> implements RouterLayout, BeforeEnterObserver {
// Implementation omitted
}
public class MainView extends PolymerTemplate<TemplateModel> implements RouterLayout {
// Implementation omitted
}
When I navigate to “/sales/products”, I see that ProductTemplate is containt in SalesTemplate and SalesTemplate is containt in MainView. If I navigate to “sales/services”, it works has design, and ProductTemplate is replace by ServiceTemplate without the parent layout beign reload.
You can see that I have put the @Route annotation on the SalesTemplate even if it is a parent layout. What I want is that if I navigate to “/sales” I can reroute to the “default” page of my choice (i.e.: “/sales/products”). If I do not use the @Route annotation, “/sales” is not view as a valid route. Since is is using a @RoutePrefix, the @Route value is “”.
With that, when I navigate to “/sales”, it work. I can see the SalesTemplate inside the MainView.
To navigate to “sales/products”, I have implemented the BeforeEnterObserver on the SalesTemplate. In the beforeEnter method, I have tried two things :
event.rerouteTo(ProductsTemplate.class)
and
UI.getCurrent().navigate(“sales/products”)
With rerouteTo, the url stays “/sales”, but the content is only the components of the ProductsTemplate without the parent layout.
With navigate, I can see that the url in the browser is now “/sales/products” but the ProductsTemplate is not inserted in the SalesTemplate.
What whould I do to move to the “default” @Route of parentLayout ?
Edit:
Here is the contents of my beforeEnter method :
@Override
public void beforeEnter(BeforeEnterEvent event) {
if(event.getNavigationTarget() == this.getClass()) {
event.rerouteTo(Lotto649Template.class);
//UI.getCurrent().navigate("vente/lotto649");
}
}
The if is there because when you navigate to Products of Services route, you also pass in the Sales beforeEnter. So I check if the target of the navigation is SalesTemplate (or this.getClass()) before changing to the default route.