Hello,
we are facing an issue with passing optional parameters using routing. Parameters are passed to another view when the app runs on BTP, but not on Prem.
The route is defined as follows:
{
name: "routname",
pattern: "thisisname/{mandaroty1},{mandatory2}/:?optional:",
target: ["targetName"]
}
This is how I navigate:
oRouter.navTo("routname", {
mandatory1: "test",
mandatory2: "test2",
"?optional": {
optional1: "value1",
optional2: "value2"
}
});
In target view: in onInit:
var oRouter = this.getRouter();
oRouter.getRoute("shapeIT").attachPatternMatched(this._onRouteMatched, this);
in _onRouteMatched:
_onRouteMatched: function (oEvent) {
var oArgs = oEvent ? oEvent.getParameter("arguments") : null;
console.log(oArgs);
}
In console of the onPrem I see as follows:
{
mandatory1: "test",
mandatory2: "test2",
"?optional": undefined
}
On BTP I see all values.
What do I miss?
You are trying to pass an object in the optional parameter. That's cleaver but I believe the problem is because of that. I would recommend using a
JSON.stringify()
to convert your optional parameters to a string and convert the string back to a JS object by usingJSON.parse()
on your_onRouteMatched
handler.