Skip to content

Match any and all query parameters in ui-router state #3038

@npm622

Description

@npm622

Apologies in advance if a GitHub issue is not the proper forum for this question -- I raised a StackOverflow question a few days back and have received zero responses, so I thought I'd turn here.

I am using UI-Router 1.x. It seems that dynamic parameters are nearly what I'm looking for, however, I do not know the names of the parameters I should be expecting, so I cannot explicitly list them and provide defaults (as dynamic parameters need).

The gist of it is, I'd like the following URLS all to route to the same component:

  • #/.../update?id
  • #/.../update?username
  • #/.../update?customerId&sandwichId

The routed component has an $onInit method that, along with a provided service, has enough information to parse whatever query parameters happen to be there. However, I cannot get the state to be activated without specifying each and every potential name of query parameter that could come through. These query parameter names are data driven, so I don't even have a finite set to do this with.

I have a non-ideal solution currently: I define one query parameter on the state, pkKeys, and then manually construct the entire query parameter string I desire and set that as pkKeys' value. In my routed component's controller, I take on additional pre-step in parsing that entire query string value by splitting on '&' and '='... Obviously it's not great, but it does align with my desired functionality.

I have tried to leverage $location.search() to supply query parameters, but have had no success with this so far.

It feels like I'm just asking for tips here, and I should just wait it out on StackOverflow. But I've spent 3 days now tinkering with the different approaches found in the ui-router guide to no avail. If this is something that just isn't supported, knowing that would at least save me some time here.

Thanks in advance for any help!

-Nick

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions