Router Query String for root

5 posts, 0 answers
  1. moosh
    moosh avatar
    9 posts
    Member since:
    Aug 2019

    Posted 24 Aug 2019 Link to this post

    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
    });
  2. Dimitar
    Admin
    Dimitar avatar
    502 posts

    Posted 28 Aug 2019 Link to this post

    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
    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.
  3. moosh
    moosh avatar
    9 posts
    Member since:
    Aug 2019

    Posted 28 Aug 2019 Link to this post

    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

  4. moosh
    moosh avatar
    9 posts
    Member since:
    Aug 2019

    Posted 28 Aug 2019 in reply to moosh Link to this post

    e.g http://mywebsite.com/?test=1234
  5. Dimitar
    Admin
    Dimitar avatar
    502 posts

    Posted 30 Aug 2019 Link to this post

    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:

    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.
Back to Top