Skip to Content
author's profile photo Former Member
Former Member

what is the right way to navigate between views?

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!?😕



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jan 10, 2014 at 01:46 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.