i am using Cross app navigation in my app I want to navigate directly to Object details

Viewed 39

i am using Cross app navigation in my app I want to navigate directly to Object details #Object-Display&/Details/000000910500453026

First time it navigates properly , but when i try to repeat the flow , it automatically navigates to root view

**#Object-Display

I just call the cross app navigator and call the app

    oCrossAppNavigator.hrefForExternal({
                        target: {
                            semanticObject: "Object",
                            action: `Display&/Details/${sProductCode}`,
                        },
                    })) ||
                "";

            oCrossAppNavigator.toExternal({
                target: {
                    shellHash: sHash,
                },
            });
Hi All, i am using Cross app navigation in my app
I want to navigate directly to Object details 
**<URL>#Object-Display&/Details/000000910500453026**

First time it navigates properly , but when i try to repeat the flow , it automatically navigates to root view 

****<URL>#Object-Display**

I just call the cross app navigator and call the app


oCrossAppNavigator.hrefForExternal({
                    target: {
                        semanticObject: "Object",
                        action: `Display&/Details/${sProductCode}`,
                    },
                })) ||
            "";

        oCrossAppNavigator.toExternal({
            target: {
                shellHash: sHash,
            },
        });

1 Answers

I had the same issue once. Are you using the cross app navigation in combination with the Admin template in SAP Portal? If so... check if the navigation item is in a multi-level hierarchy. When you use any form of navigation to an application that is located in the lower levels of the menu hierarchy then the Shell.controller.js is automatically routing you back to the root.

To solve this, I used a SAP Portal plugin and hacked the Shell.controller.js.

Code snippet:

        /**
         * OVERRIDE! sap.ushell.services.cp.designtime.renderers.cp.admin.Shell -> _selectControlByHash
         * Default SAP Portal behaviour is changed to support deep-link navigation.
         * @param {navigation intent} h
         */
        customSelectControlByHash(h) {
            const a = this.arrRefControls;
            const f = this.getView().fixedItemsList;
            let b;
            let l;

            h = h.replace("#", "");
            if (a) {
                b = a[h] || a[h.split("?")[0]];
                if (!b) {
                    const s = sap.ushell.Container.getService("SiteService").getSiteModel();
                    const p = s.getAllPagesAndApps();
                    const d = s.getPageByAlias(p, h);
                    if (d) {
                        b = a[d.getIntentAction()];
                    }
                }
                if (b) {
                    if (f) {
                        f.setSelectedItem();
                    }
                    l = b.getParent();

                    /** Replacing ORIGINAL CODE **/ 
                    // if (l && l.setSelectedItem) {
                    //  l.setSelectedItem(b);
                    // } else if (l && l.setExpanded) {
                    //  l.setExpanded(true);
                    //  if (this.siteService.siteModel.isAdminSite() && !this.siteService.isDesignTime()) {
                    //      const o = new sap.ui.core.CustomData({
                    //          key: "refresh",
                    //          value: true,
                    //      });
                    //      b.addCustomData(o);
                    //  }
                    //  if (b._selectItem) {
                    //      b._selectItem();
                    //  }
                    // }
                    /** End ORIGINAL CODE **/ 

                    /** Start CUSTOM CODE **/
                    // prevent using b._selectItem() as this is triggering a re-routing event.

                    if (l && l.setExpanded && !l.setSelectedItem) {
                        //Collapse all others
                        l.getNavigationList().getItems().forEach(e => e.getProperty("expanded") && e.setProperty("expanded", false));
                        // Expand target
                        l.setExpanded(true);
                        if (b._selectItem && this.siteService.isDesignTime()) {
                            b._selectItem(); // Keep behaviour only when in DesignTime mode (Administration site)
                        } else if (l && l.getNavigationList) {
                            l.getNavigationList().setSelectedItem(b); // Instead of using _selectItem(), use setSelectedItem() using the parent navigation list.
                        }
                    } else if (l && l.setSelectedItem) {
                        l.getItems().forEach(e => e.getProperty("expanded") && e.setProperty("expanded", false));
                        l.setSelectedItem(b);
                    }
                    /** End CUSTOM CODE **/
                }
            }
        }

        /* Hacking the SideNavigation via "byId()" and via DOM Manipulation below.
         * It is impossibility to extend or redefine the SideNavigation in the adminTemplate.
         * This plugin is too late.
         */
        enhanceNavigation() {
            try {
                // Load the custom icons
                //ToDo: Can we remove IconFontLoader here and move it to library.
                new IconFontLoader().loadCustomIcons().then(function () {
                    
                    if (this._applyCrossAppNavigationFix) {
                        // Inject custom logic to override: sap.ushell.services.cp.designtime.renderers.cp.admin.Shell -> _selectControlByHash
                        // This must fix the CrossApplicationNavigation logic when deep-linking.
                        const oMainShellController = sap.ui.getCore().byId("mainShell").getController();
                        if (oMainShellController && oMainShellController._selectControlByHash) {
                            oMainShellController._selectControlByHash = this.customSelectControlByHash.bind(oMainShellController);
                        }
                    }....
Related