ui-router icon indicating copy to clipboard operation
ui-router copied to clipboard

Transition to the same state

Open bbshopadmin opened this issue 13 years ago • 3 comments

For a game app i have multiple game levels and only one game view. When level 1 is finished level 2 is loaded. So i have to transitionTo the same game view again. The game view then loads the new level data itself.

As workaround i have two states with the same content but different names. Then i transitionTo either one or the other. But i would like to do it in a more elegant way.

To avoid browser history back/next the app has no urls/deeplinking - so url parameters or routes can't be used.

Is there a better way of doing all this?

bbshopadmin avatar May 30 '13 16:05 bbshopadmin

Just give your state a 'level' parameter. Parameters work even when you don't have a URL, you just declare them in the 'params' array, e.g. params: ['level'].

Then just $state.transitionTo('game', { level: 1 }). When you transition to the same state with different parameters, you get a new instance of that state.

On Fri, May 31, 2013 at 4:11 AM, bbshopadmin [email protected]:

For a game app i have multiple game levels and only one game view. When level 1 is finished level 2 is loaded. So i have to transitionTo the same game view again. The game view then loads the new level data itself.

As workaround i have two states with the same content but different names. Then i transitionTo either one or the other. But i would like to do it in a more elegant way.

To avoid browser history back/next the app has no urls/deeplinking - so url parameters or routes can't be used.

Is there a better way of doing all this?

— Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/ui-router/issues/156 .

ksperling avatar May 30 '13 22:05 ksperling

Works great. Sorry, i couldn't find that in the wiki. Thank you!

bbshopadmin avatar May 30 '13 23:05 bbshopadmin

Yeah, I had the same problem.

sheerun avatar Jul 26 '13 19:07 sheerun