Router handling of optional query params

5 posts, 0 answers
  1. Ryan
    Ryan avatar
    27 posts
    Member since:
    Jan 2013

    Posted 16 Dec 2013 Link to this post

    I'm using kendo spa support in 2013.3.1119

    If I want to have optional query parameters, it is not clear how to do that. I've got something to work, but it feels broken, or inconsistent.

    See fiddle

    I'm trying to support a route with no :id param, but has optional query params, like this:
    router.route("/images(?:params)", function (params) {

    I could only make this work by having a dummy first parameter since "undefined" is passed as arg1:
    router.route("/images(?:params)", function (dummy, params) {

    That seems like a bug. 

    I found if I have an :id param in my route, like:
    router.route("/images/:id", function(id, params) {

    Then the optional query params are implicitly passed in the second argument. This is how I'd expect it to work (with or without an :id param).


    In summary, should I be trying to take advantage of the automatic/implicit second argument that contains the query params? Or should I be including the (?:params) in my route url?

    Am I missing something? Is there a bug here?


    Thanks
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 18 Dec 2013 Link to this post

    Hi Ryan,

    You should not include the (?:params) in your route. If there are any query string parameters in the URL they will be parsed and passed as last argument in the callback function. If the id is optional please define it as an optional segment.

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Ryan
    Ryan avatar
    27 posts
    Member since:
    Jan 2013

    Posted 18 Dec 2013 Link to this post

    You're saying I should set it up like this?

    router.route("/case3(/:id)", function (id, params) {

    So, I tried that here

    Problem is, that the route doesn't get called for:

    <a href="#/case3?a=1000">
  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 20 Dec 2013 Link to this post

    Hi Ryan,

    I can confirm that this is a bug in the way router matches URLs with query string parameters and missing optional segments.
    We will log this issue and try to fix it as soon as possible. I am afraid that I cannot suggest a suitable workaround except using a dummy segment.
    Please accept my apology for the inconvenience caused.

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 14 Jan 2014 Link to this post

    Hi Ryan,

    I am glad to inform you that the issue is fixed and the fix is available in the latest internal build. Please download it and give it a try.

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready