Router with nested component - documentation incomplete?
UI5 developer guide mentions, it is possible to nest components with each component having its own (sub)routes. https://openui5.hana.ondemand.com/#docs/guide/2c66fb3eb775426087401117cfa6a94e.html
I think it is a great feature, helping to modularize bigger applications. Or it were great, if I knew how to use it.
The documentation mentions, the child route should be declared with parent attribute and nothing else.
What we have is the following:
- parent component
- child1
- child2
In the parent we define two routes that lead to two views. One view has component container and embeds component child1, the other has container with child2.
The path /child1 opens the view with child1 component.
Child1 has its own routes that refer to parent. We expect the path /child1/view1 to trigger the /view1 route in child1 component and display the respective view.
This does not work, as the router in the parent component tries to handle the complete path and it obviously does not have such a path defined. I am wondering, how it should know that there are some paths defined in the child components. Should we somehow refer to the child components in manifest of the parent component? Is is correct to use component container as described above?
I saw similar question on Stack Overflow (https://stackoverflow.com/questions/39754764/sapui5-routing-between-different-components). Since it has not been answered there for over half a year and I could not find anything else on this topic, I suppose the knowledge, how to achieve this is generally missing. Therefore, I am asking my questions here, in hope the topic could be cleared by some UI5 insiders.
Hi rasmk,
thanks for your explanation. I have an imagination of what the problem could be, but it is hard to say without the corresponding code. Could you please share your configuration, or at least a simpified version of it?
I have prepared a jsbin, which shows the example in our documentation. You may just modify it to have an equivalent to your own config: https://jsbin.com/zifugihiho/edit?html,output
Best regards Benedikt
Has anyone managed to find any further information on this issue? I'm trying to implement the same sort of thing but getting nowhere at the moment. I can't seem to find any practical examples.
I've create a repository where I'm attempting to have a play around but so far no had any joy. (https://github.com/bawder/ui5nestedcomponents)
Is there a proper way to navigate back to the parent component?
For the moment I am using event Bus between to send an event to parent so that it can handle the routing.
maybe you can wrap child component inside a ComponentContainer ?
I have a (sort of) working demo here if you are still interested in this.
I also struggled with this scenario, and eventually came up with my own alternative: https://blogs.sap.com/2019/08/23/ui5-nested-routing-with-reusable-components/
What freaks me out, is that the standard supported way does not work propertly, and even requires you to reference the parent route in the subcomponent! A subcomponent must be parent-agnostic! That's just bad software architecture.
I've created an internal incident 2080375760. The status of the issue will be updated here in GitHub. Regards, Diana
Hi @FiddleBe and @rasmk , UI5 developed a new feature called "Routing in Nested Components". See https://openui5.hana.ondemand.com/topic/fb19f501b16e4e4991eb6a017770945b. This feature should provide the power you need for your requirements. If you have any further comments or improvement proposals, don't hesitate to get in touch with us by opening a new issue. All the best, Florian