cancel
Showing results for 
Search instead for 
Did you mean: 

routing parameter not working

Former Member
0 Kudos

Hello Everyone,

I am trying to send the data from one view to another using routing but when I am writing the code its not sending the parameters which I am defining in the navTo function below is the code which I am trying to use .


edit : function(evt){

                           sap.ui.core.UIComponent.getRouterFor(this).navTo("app",{id : "5"});

          }

as shown above I am trying to send the id to the view app but in the init method of app view I am not getting the argument id its showing as undefined.

below is the code for init method


sap.ui.core.UIComponent.getRouterFor(this).attachRouteMatched(function(oEvent){

           

             console.log(oEvent.getParameter("arguments").id);

             if(oEvent.getParameter("name") === "app"){

             var context = new sap.ui.model.Context(view.getModel(),oEvent.getParameter("arguments").id);

             alert(context+"hello");

             }

       },this);

when I am trying to run the above code its showing me as undefined in the alert box.

So can anyone help me out where I am making a mistake .

Thanks in advance,

Anshul D

Accepted Solutions (1)

Accepted Solutions (1)

kedarT
Active Contributor
0 Kudos

Hi Anshul,

Do you have the argument "id" mentioned in the pattern "app" in the routes of your component.js file.

It shoud be something like this

pattern : "{product}/:tab:",

name : "product",

view : "Detail"

Look at the developer guide - Step 3: Navigation and Routing - SAPUI5 SDK - Demo Kit

Hope this helps.

Former Member
0 Kudos

hi Kedar,

yes I have not defined that in component.js but I have one doubt I'll define this in sub route right ??

below is the code

{ pattern : "app",

name : "app",

view : "app",

subroutes : [

                         {

                                   pattern:"{id}",

                                   name:"app2",

                                   view : "app2"         

                         }

                    ]

is the above code correct or do I need to add target control and target aggregation

Thanks,

Anshul

kedarT
Active Contributor
0 Kudos

Yes, You would need to define targetAggregation and the other thing which i saw in your subroute you mentioned "{id}" as the pattern. If you do not have a pattern for the subroute then change this to something like this

pattern: "sub/{id}"

Also i am not sure why would you use subroute if you have just navigate to a single view/page.

Hope this helps.

Former Member
0 Kudos

hi  kedar ,

thank you so much.

Its working fine now and I am getting both the arguments contextPath and id .

Instead of using sub route I have declared both the arguments in route .

{

pattern : "app/{contextPath}/:id:",

name : "app",

view : "app",

}

Thanks again,

Anshul Dharmadhikari

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

try just oEvent.getParameter("id") in attachRouteMatched handler