How to handle multipleparams in dynamic way.
I have routing with multiple params like this.
routes: {
'home/:id': 'onHomeId',
'home/:id/:param1': 'onHomeId',
'home/:id/:param1/:param1Value': 'onHomeId',
'home/:id/:param1/:param1Value/:param2/:param2Value': 'onHomeId',
'home/:id/:param1/:param1Value/:param2/:param2Value/:param3/:param3Value': 'onHomeId',
'home/:id/:param1/:param1Value/:param2/:param2Value/:param3/:param3Value/:param4/:param4Value': 'onHomeId',
}
Instead of writing this much I want some dynmic way to generated because params can grow.
so here is what i am trying.
onHomeId : function(){
let _this = this,
hashValue = location.hash,
params = location.hash.split("/");
/* code where i am using params */
}
I am taking whole url and braking this and then working on that
can anybody explain me what the best I can do.
ExtJS Router is not really meant for passing variable number of parameters, like a URL query string. ExtJS Router can be used to keep track of your application's state and store it in the browser history, so your users can navigate back and forward, and link into specific parts of your application, like it were not a Single Page Application.
The method that you specify for a route will get all parameters from the route, in that order. So route
home:/param1needsfunction(param1), routehome:/param1/:param2afunction(param1, param2)etc. These are not key-value pairs, like?param1=1¶m2=2. You can use them likeyourdomain.com#home/1/2, and the function handling this route will receive1and2as parameters, in that order, you can't specify parameter names in the route.There is a possibility to set routes dynamically, not in the class declaration, using
setRoutemethod of the controller, and execute it when your application is initialised. But it won't really help you, because you would still need functions with 1,2,3 etc. parameters.So you have two options, as far as I understand:
home/:myallparams, and in thefunction(myallparams)you can try to separate its parts. But you can easily get into troubles with special characters and I don't really recommend this approach.?param1=1¶m2=2in your URL you can use the following code to extract the parameters in your ExtJS code: