Hello,
I’m trying to get query string values for a root route but parameters seems to be undefined.
e.g for url : https://mywebsite.com/?test=hello
thanks for your help.
var
router =
new
kendo.Router();
router.route(
"/"
,
function
(params) {
console.log(params);
// undefined
});
4 Answers, 1 is accepted
0
Hi moosh,
The following Dojo snippet, which is based on Router Query String help section, shows in browser's console that on navigating to /?test=hello url, the params are test: hello. Before that navigation params are undefined, as initially navigation is to "/". And this Dojo snippet shows how params can be tracked on router's change event as well. I hope this helps.
Regards,
Dimitar
Progress Telerik
The following Dojo snippet, which is based on Router Query String help section, shows in browser's console that on navigating to /?test=hello url, the params are test: hello. Before that navigation params are undefined, as initially navigation is to "/". And this Dojo snippet shows how params can be tracked on router's change event as well. I hope this helps.
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0

moosh
Top achievements
Rank 1
answered on 28 Aug 2019, 06:49 PM
Hi,
Thank you.
Yes it works like that, but if you copy paste root url with parameters in your browser directly (in a new tab for example), the router does not get the parameters.
moosh
0

moosh
Top achievements
Rank 1
answered on 28 Aug 2019, 06:50 PM
e.g http://mywebsite.com/?test=1234
0
Hi moosh,
Kendo Routers uses the fragment url part (#page). Navigating to the url without # results in a routerMissing event firing, which may be used for redirecting to root, as discussed in the following forum thread about the same case.
As an alternative approach I tried handling the URL in routerMissing event as follows, but I still could not get it working:
I hope it may help you to find a solution for navigating to the query string.
Regards,
Dimitar
Progress Telerik
Kendo Routers uses the fragment url part (#page). Navigating to the url without # results in a routerMissing event firing, which may be used for redirecting to root, as discussed in the following forum thread about the same case.
As an alternative approach I tried handling the URL in routerMissing event as follows, but I still could not get it working:
router.bind(
"routeMissing"
,
function
(e) {
console.log(
"missing route event"
, e);
var
paramName = Object.keys(e.params)[0];
var
newURL =
"/?"
+ paramName +
"="
+ e.params[paramName]
router.navigate(newURL);
});
I hope it may help you to find a solution for navigating to the query string.
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.