Don't reload page when browser back button is pressed

14,106 views
Skip to first unread message

Pushpendra Kumar

unread,
Mar 19, 2014, 3:36:38 PM3/19/14
to ang...@googlegroups.com
Hello,



               I have a list page and on click of any list item i go to show page.
               Now if I press browser back button then list route called and re-render the list page.
               But I don't want this. I want that on pressing browser back button previous page should be seen without reloading it.
               Can we hide it while we are going to show page and when come back then show this?
               Please suggest me the trick.

               List Page ----> show page
                                                 list page(but it should not be reloaded) <-----  browser back button 


Regards,
Pushpendra

Luke Kende

unread,
Mar 20, 2014, 2:03:34 AM3/20/14
to ang...@googlegroups.com
Yes, this is one of the challenges I ran into with routing and angular.  Anytime the route changes, the controller and the template are loaded anew.  I think we expect angular to behave like cached pages when users hit the back button and it's just there, but it's not the same context with deep linking.  A couple of ideas:

1.  Don't put the item page in a new route, just ng-hide/ng-show what you want on click and give user a back button so they don't use the browser back button.
2.  Store your list items so that they are not reloading from ajax and the back button will still re-render them very quickly.

Pushpendra Kumar

unread,
Mar 20, 2014, 3:41:00 AM3/20/14
to ang...@googlegroups.com
Thanks Luke.

Can I customize browser back button in my controller.
I will get browser back button event and set some vars in $rootscope.
Using that var i will hide and show the list page and ite detail page.


Pushpendra


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Luke Kende

unread,
Mar 20, 2014, 2:21:48 PM3/20/14
to ang...@googlegroups.com
I don't think angular can be aware that the actual back button was pressed, but it can respond to route changes:

$scope.$on('$routeChangeSuccess',function(){
  console.log('location is now', $location.path())
})


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/2OkTqU5GiOw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

Sander Elias

unread,
Mar 20, 2014, 2:43:37 PM3/20/14
to ang...@googlegroups.com
Luke, Pushpendra,

If you switch to html5mode, you gain (some) control over the back-button. This enables the use of the history api
However, this works only well in evergreen browsers tough. no IE<10 (perhaps even 11)

Regards
Sander

Luke Kende

unread,
Mar 21, 2014, 12:35:13 AM3/21/14
to ang...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages