Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Previous to page with ui-router without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
I have a SPA system and to do the routes I am using the ui-router $stateProvider.state and this case the browser not save the history to that I can return to last page, I tried many things and didn’t work yet, in this case I need that when the user clicked in Cancel button he return to last page, How I do this?
Answer
You can add an event on stateChangeSuccess
to keep in memory your last state:
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) { /* Here, from is the previous page you want to recover */ /* For example: */ $state.previousState = from; });
You will be able to use it in $state.go
:
$state.go($state.previousState.name);
Note: using stateChangeStart
may work as well.
We are here to answer your question about Previous to page with ui-router - If you find the proper solution, please don't forgot to share this with your team members.