router icon indicating copy to clipboard operation
router copied to clipboard

Handle multiple values for same url query string parameter name as array.

Open zedL opened this issue 8 years ago • 3 comments

I'm submitting a feature request

  • Library Version: 1.2.1

Please tell us about your environment:

  • Operating System: Windows [10]

  • Node Version: 6.4.0

  • NPM Version: 4.0.3

  • Browser: all

  • Language: all

Current behavior: Assuming this url/route is given: /rooms-view?roomId=abc&visible=true&roomId=def&visible=false

Aurelia currently handle only the last found match.

aurelia-querystring-handling

Other frameworks like ASP.NET Core can hanlde multible values for same query parameter.

aspnet-core-querystring-handling

Expected/desired behavior: In the given example I would expect for each key an array of values in the queryParams object.

queryParams: {
 roomId: ['abc', 'def'],
 visible: [true, false]
}
  • What is the motivation / use case for changing the behavior? Bookmarkable URLs from where I can extract arrays of same data structure.

@AshleyGrant knows what I mean ;-)

zedL avatar Mar 05 '17 17:03 zedL

Thanks to @PWKad on aurelias Gitter channel there is always a way aurelia can handle it. If I rewrite the url to: /rooms-view?roomId[]=abc&visible[]=ture&roomId[]=def&visible[]=false the things work like expected.

Maybe you want to support the other syntax to, so I let this issue open but will not cry when you close it :)

zedL avatar Mar 05 '17 18:03 zedL

Readable URL´s

After playing around with the array syntax and the routers navigateToRoute method I would like to point you to some behaviour.

I want that my app can handle this url.

normal style /rooms?id=GuUwRtiTWz0&v=true&id=1i7pyGzRorX&v=true

array style /rooms?id[]=GuUwRtiTWz0&v[]=true&id[]=1i7pyGzRorX&v[]=true

The array style is currently supported by aurelias router and I can generate a route/url with following code:

let routeName = 'rooms';
let routeOptions = { id: ['GuUwRtiTWz0', '1i7pyGzRorX'], v: [true, true] };
router.navigateToRoute(routeName, routeOptions, { replace: true, trigger: false });

because brackets should be encoded the router generates following URL:

url encoded array style /rooms?id%5B%5D=GuUwRtiTWz0&id%5B%5D=1i7pyGzRorX&v%5B%5D=true&v%5B%5D=true

Brackets in url´s are ugly, but encoded (and they should) are more ugly. I changed my mind and vote for the normal style.

zedL avatar Mar 07 '17 16:03 zedL

Indeed. AFAIK the bracket style is some whacky convention that PHP came up with. Standards-oriented Aurelia should be using /people?id=1&id=2.

RomkeVdMeulen avatar Aug 07 '18 13:08 RomkeVdMeulen