Search code examples
javascriptangularjsangular-ui-routerurl-routing

Angularjs redirect to state using a url


Usually if I want to send a user to a specific state, I just do:

$state.go('state_name');
$state.transitionTo('state_name');

And that will usually bring them to /state_name. However, I have a particular state that I am trying to send them to that has a variable in it like /state_name/:variable and I can't seem to figure out how to redirect them to /state_name/whatever_I_choose.

Can anyone help me figure this out? I am using ui-router as well.


Solution

  • You should use $state.go which call $state.transitionTo internally

    For passing variable in route you could have pass json with list of params with there values. $scope.variable is changed from the controller that would pass value while redirecting.

    $state.go('state_name',{variable: $scope.variable });