2

I want to use component.js in js view but it is taking rootview for searching xml file. Please help how should I write this file so that I can do routing in js views.

jQuery.sap.declare("com.resident.Component");
sap.ui.core.UIComponent.extend("com.resident.Component", {

metadata : {
  rootView : "com.resident.residentbhartiya.App",
  routing : {
   config : {
    targetsClass : "sap.m.routing.Targets",
    viewPath : "com.resident.residentbhartiya",
    controlId : "rootControl",
    controlAggregation : "pages",
    viewType : "JS"
   },
   targets : {
    page1 : {
     viewName : "loginpage",
     viewLevel : 0
    },

    page2 : {
     viewName : "homepage",
     viewLevel : 1
    }
   }
  }
},

init : function() {
     sap.ui.core.UIComponent.prototype.init.apply(this, arguments);
     this.getTargets().display("page1");
},

});
Priyanka Maurya
  • 413
  • 3
  • 7
  • 18
  • Does this answer your question? [Navigating to a different (JS)View - Unable to access Router](https://stackoverflow.com/questions/60814017/navigating-to-a-different-jsview-unable-to-access-router) – Boghyon Hoffmann Apr 22 '21 at 22:27
  • Also: _JS View_ is now deprecated. Use [Typed View](https://openui5.hana.ondemand.com/topic/e6bb33d076dc4f23be50c082c271b9f0) instead. – Boghyon Hoffmann Apr 22 '21 at 22:28

1 Answers1

0

You can give rootView a configuration object instead of a string as described in the documentation:

Specifies the root view that shall be opened; can be the view name as a string for XML views, or the view configuration object with viewName for the view name as a string and type for the type (enumeration of sap.ui.core.mvc.ViewType) and other properties of sap.ui.core.mvc.view.

So it should look like this:

metadata:{
   rootView: {
      viewName: "com.resident.residentbhartiya.App",
      type:"JS"
   } 
  ... 

But im not shure if it shouldn't be viewType:"JS" this time too. You should try that too, if type doesn't work.

schnoedel
  • 3,918
  • 1
  • 13
  • 17