Fiori — Cross application navigation; Handling startup parameters?

[亡魂溺海] 提交于 2019-12-04 17:34:09

The parameter must be retrieved as

var oComponentData = this.getComponentData();
if (oComponentData.startupParameters) {
    oRouter.navTo("SomeView", {
        someId : oComponentData.startupParameters.someID[0],
    }, false);

as you write. In Fiori applications, the startup parameters injected into the Component data of your constructor may have been renamed, enriched by further default values etc.. Thus they may be distinct from the parameter one observes in the url. Applications are advised to refrain from trying to inspect the URL directly.

If one supplies a very long set of url parameters, one will observer that the FLP replaces some of them with sap-intent-param=AS123424 ("compacted URL") to work around url length restrictions on some platforms and in bookmarks, in the getComponentData().startupParameters one will receive the full set of parameters).

As to the second question. No, there is currently no way to "cleanse" the URL and avoid the redundancy between and inner app route.

SemObject-display?someID=102343333&/SomeView(102343333)/ which after navigation may look like SemObject-display?someID=102343333&/SomeView(102343999)/

App was started with 102343333, but then user navigated within the app to another item (102343999).

Any change in the "Shell-part" of the has (SemObject-display?someID102343333) will lead to a cross-app-navigation (reinstantiation of your component) with a different startupParameter.

(There are cases where this is desired in the flow, e.g. a cross navigation from a OrgUnit factsheet to the parent OrgUnit factsheet via a link).

There were ideas within SAP to fuse the inner-app routes and the intent parameters, but they were not carried out, as it's mostly url aesthetics.

Note: To support boomarking, one has to respect both startup parameters and inner app route during component instantiation, assuming the user created a bookmark on

SemObject-display?someID=102343333&/SomeView(102343999)/ (While he was looking at 9999(!)).

When reinstantiating the app, the inner app route should take higher precedence than startup-parameters.

So amend the code to:

var oComponentData = this.getComponentData();
if (oComponentData.startupParameters) {
    if (sap.ui.core.getHashChanger().getHash()=== "") {
         // if no inner app route present, navigate 
         oRouter.navTo("SomeView", {
               someId : oComponentData.startupParameters.someID[0],
         }, false);
    }

}

https://sapui5.netweaver.ondemand.com/#docs/api/symbols/sap.ushell.services.CrossApplicationNavigation.html

SAP Fiori Launchpad for Developers, Navigation Concept http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/907ae317-cb47-3210-9bba-e1b5e70e5c79?QuickLink=index&overridelayout=true&59575491523067

I was having issues navigating from a Fiori elements app in to a deep page in a freestyle UI5 app and then answer from @user6649841 provided most the solution for my requirement.

In my instance, navigating from the elements list report (app "A") in to the target freestyle app (app "B") I didn't want the worklist/initial page in app B to display at all and instead go straight to the detail page without a flickering of the initial app screen.

The below worked for me, note though it doesn't solve the ugly URL issues. In my case I'm not fussed about it as my nav back will nav back to the elements list report (App A) and never show the worklist page in App B so the user will never make another search on top of this URL which would lead with inconsistent inner and outer keys

Component.js (at end of init function after all the standard sap code, but before router initialization):

var oComponentData = this.getComponentData();
var startupParams = oComponentData.startupParameters;

 if (startupParams && startupParams.myQueryStringParamName && startupParams.myQueryStringParamName[0]) {
    //In my case using hash changer as I dont want the original landing page (default route) to be
    //in the history, so the detail page loads straight away and nav back will cause to nav back to App A
    var hashChanger = sap.ui.core.routing.HashChanger.getInstance();
    hashChanger.replaceHash("detailPage/" + startupParams.myQueryStringParamName[0]);
}
//initialise after the above so the new hash is set and it doesnt initially load the
//page assigned to the default route causing a flickering and nav slide effect
this.getRouter().initialize();

Looking at the UI5 SDK in UI5 1.48 and above in the initialize method of router you can pass in a boolean to tell it to ignore the initial hash so possibly can do a simpler implementation in newer releases of UI5

Is Component.js right place for handling the startup parameters?

Depends,if you have multiple views and you want to dynamically route based on the incoming parameters. Else you can handle in specific view also.

Your second question was not quite clear to me.

Nevertheless, if you want to only specific cases of startup parameters, then from Source App, set some flag to understand where is the request coming from and handle accordingly. So this way, your normal navigation won't be tampered.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!