ui-router / angular

UI-Router for Angular: State-based routing for Angular (v2+)
https://ui-router.github.io/ng2/
MIT License
354 stars 134 forks source link

Request param from the url query string return string instead of array for param with multiple value #22

Closed quang-tuan closed 7 years ago

quang-tuan commented 7 years ago

When passing an array as search query through the param using the [uiPrams] everything work as expected where the param is returned as array of string. However, passing the search query through the url such as ?param=test1&param=test2 the app is returning a string (test2) instead of array of string.

Plunker example has 2 link where one is using the uiSref, the other one is using the href https://plnkr.co/edit/HNeb0egtVUFUt7eNPpfZ?p=preview

I believe the issue is caused by this line in location.ts

loc.search = <any> (() => {
      let queryString = splitOnHash(splitOnQuestionMark(locSt.path())[1])[0];
      return queryString.split("&").map(kv => splitOnEquals(kv)).reduce(applyPairs, {});
    });

The applyPairs function return key, value assumed that keys are unique.

christopherthielen commented 7 years ago

This will be fixed in beta.4: https://plnkr.co/edit/hZ2Lehs2IOxw1qdufPF4?p=preview

We're now using a wrapper around the "vanilla" location api from ui-router-core which properly manages arrays

christopherthielen commented 7 years ago

fixed in beta.4