cancel
Showing results for 
Search instead for 
Did you mean: 

what is the right way to navigate between views?

Former Member
0 Kudos

Hi , im newbie in sapui5 development and i saw there are 2 different ways to navigate between views:

the first way ive seen is just to do something like : app.to("ProductDetail");

the secound way is:

var bus = sap.ui.getCore().getEventBus();

bus.publish("nav", "to", {

  id : "Product"

});


, as I see , in order to use the secound way (using the EventBus) its needed to implement some more code from the "Navigation Demo App" example , this I say according to the sapui5 best practices link: Documentation/AdvancedTopics/Mobile/BestPractice/Navigation – SAPUI5 Wiki (TIP CORE User Interface)...



so, what is the right way!?



Accepted Solutions (1)

Accepted Solutions (1)

qmacro
Developer Advocate
Developer Advocate
0 Kudos

As in many areas there are different ways and often there isn't a particular right or wrong way. One of Perl's mottos is TMTOWTDI (pronounced "tim-toady") meaning "There's More Than One Way To Do It". But I digress ...

The two different ways you mention above, however, amount to the same thing.

The "to" that you're referring to is a method in the NavContainer control that performs the navigation. This is explicit in your app.to() example.

The EventBus-based navigation is just a way of sending a navigation signal from the controller of a view (that doesn't have a direct link to the NavContainer or App control) to the part that can make the navigation happen. Eventually, an app.to() type call will be made to satisfy that published signal.

So if you have, say, an App control in your root view's controller, you should either expose it to the other controllers, or use the event bus to subscribe to navigation events that are then published onto it, "independently", from the controllers of other views.

Have a play around with both techniques to get a better feel for them.

Cheers!

dj

Former Member
0 Kudos

OK, thanks for your reply! I just want to quote from the "best practices":

' When lazy loading pages from the server you never know if the desired page has already been loaded. To achieve this the sap.ui.core.EventBus is used."

it won't matter if i'll use directly "app.to("view");" ?

Answers (0)