Skip to content

The params option in state configurations doesn't handle well deep objects #1562

@tbassetto

Description

@tbassetto

I may be using the params options when configuring a state for an unexpected scenario.

I have a login page defined like this:

$stateProvider.state('login', {
    controller: 'LoginCtrl',
    templateUrl: '/scripts/core/login.html',
    url: '/login',
    params: {
        goToNextState: null,
        goToNextParams: null,
        reason: null
    }
});

I used params because I want to pass information to the login page (like why someone would end up being redirected to that page and where to go next once successfully logged in) without "polluting" the URL.

If an auth error happen I used the following code:

$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) {
    if (error.type === 'auth') {
        $state.go('login', {
            goToNextState: toState.name,
            goToNextParams: toParams,
            reason: 'Auth error yadda yadda'
        });
    }
    // ...
}

With ui-router 0.2.12 I see two issues:

  1. The params appears in the URL as query strings, I was expecting them to be invisible. Can I "fix" that?
  2. In LoginCtrl, $stateParams.toParams equals the string "[object Object]" instead of being the toParams object from before. Is that an expected behavior or a bug?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions