You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tested and found that $state.transitionTo() does not use the current $stateParams (or $state.params) to populate the target params if they're not included in the second parameter.
For example, if the user is on the url /contacts/Alice
and $stateParams = {"user" : "Alice"}
and clicks on a link with with ng-click="$state.transitionTo('user.roles')"
given state definition .state('user.roles', { url: '/contacts/{user}/roles' }
an error is thrown.
If the ng-click is changed to ng-click="$state.transitionTo('user.roles', {})"
then the new url is /contacts//roles.
I checked the source code and I don't see a way to use existing $stateParams by default in the destination route.
I got around it by using ng-click="$state.transitionTo('user.roles', $stateParams)"
but I would also like the ability to override the existing $stateParams if needed.
Is this something that will be implemented in the future? For now I can use the mentioned workaround or even use a wrapper function that combines the current $stateParams with new params using jQuery.extend({}, $stateParams, {newParam1: newParam1Value}).
The goal would be to save time from writing this: ng-click="$state.transitionTo('user.roles', {user: $stateParams.user})" because I have many routes with several params.
Thanks, and thanks for creating this useful module!
The text was updated successfully, but these errors were encountered:
That's correct, this is not currently implemented.
The plan is to augment the current behaviour so that any parameters that are shared between the two states will be defaulted from the current $stateParams (however this won't apply to parameters that are named the same "by coincidence" to avoid unintended behaviours).
Awesome! Would be great if ui-router gets assimilated into angular base. If not, as long as it's the defacto standard for routing/state management that would be fine too.
I've tested and found that
$state.transitionTo()
does not use the current$stateParams
(or$state.params
) to populate the target params if they're not included in the second parameter.For example, if the user is on the url
/contacts/Alice
and
$stateParams = {"user" : "Alice"}
and clicks on a link with with
ng-click="$state.transitionTo('user.roles')"
given state definition
.state('user.roles', { url: '/contacts/{user}/roles' }
an error is thrown.
If the
ng-click
is changed tong-click="$state.transitionTo('user.roles', {})"
then the new url is
/contacts//roles
.I checked the source code and I don't see a way to use existing $stateParams by default in the destination route.
I got around it by using
ng-click="$state.transitionTo('user.roles', $stateParams)"
but I would also like the ability to override the existing $stateParams if needed.
Is this something that will be implemented in the future? For now I can use the mentioned workaround or even use a wrapper function that combines the current
$stateParams
with new params usingjQuery.extend({}, $stateParams, {newParam1: newParam1Value})
.The goal would be to save time from writing this:
ng-click="$state.transitionTo('user.roles', {user: $stateParams.user})"
because I have many routes with several params.Thanks, and thanks for creating this useful module!
The text was updated successfully, but these errors were encountered: