Search code examples
angularjsangular-ui-router

How to pass query string parameters through URL


I am using this:

$state.go("/path/to");

I want to do this:

$state.go("/path/to?param=myParam");

But this is not working.

I have tried:

$location.path("/path/to?param=myParam");
$location.path("/path/to").search({param: "myParam"});

Both of them actually change the url but not updated the angularjs app - since this is not connected to the actual router.

How can I pass query string parameters using AngularJS ui router? Note I know I can pass a full url path like this:

/path/to/param/myParam 

But I need in this case that it will be query string params.


Solution

  • According to the documentation $state.go takes another parameter that you can use to pass query string.

    $state.go("/path/to",{param:myParam});