This is a migrated thread and some comments may be shown as answers.

Router handling of optional query params

4 Answers 119 Views
SPA
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 16 Dec 2013, 11:58 PM
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

4 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 18 Dec 2013, 05:25 PM
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!
0
Ryan
Top achievements
Rank 1
answered on 18 Dec 2013, 05:47 PM
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">
0
Alexander Valchev
Telerik team
answered on 20 Dec 2013, 01:01 PM
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!
0
Alexander Valchev
Telerik team
answered on 14 Jan 2014, 12:52 PM
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!
Tags
SPA
Asked by
Ryan
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or