The Problem...

The Implementer should have the ability to write simple redirects using $urlRouterProvider.when to invoke another state with the same, expected URL-parameters:

$urlRouterProvider.when('/hook/route', '/that/other/route');

This should provide the correct $sateParams needed for the target state. For example, if the URI /hook/route?token=X is called, the target state should have $stateParams.token === 'X' -- given that this parameter is configured within the $stateProvider ({... url: '/that/other/route?token' ...});

The conventional way [in Stackoverflow-land] looks like the following:

$urlRouterProvider
    .when('/hook/route', redirect)
    .otherwise('/');

function redirect($state, $stateParams) {
    $state.go('app.otherState', { token: $stateParams.token });
}

This seems very overkill for a simple redirect-with-parameters action -- especially if many redirects are needed.

The answer I'll provide below shows a very-low-overhead approach, which unfortunately, has not been spot-lighted in other StackOverflow threads regarding this topic...

share|improve this question

... Solution

Match your URI's parameters against those expected by your target state:

$urlRouterProvider
    .when('/hook/route?token', '/route?token')
    .otherwise('/');

Cheers!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.