Reputation: 1992
I have an angularJS application that is using one tpl.html page to navigate and communicate with the backend model. I want to be able to use the browser back/next buttons to navigate within the SPA. Is this possible? I tried history.back(); for the back button but that didn't work.
Upvotes: 0
Views: 400
Reputation: 123
In order to achieve that, you will need to use UI Router's state functionality. Below is an example from Scotch.io
:
$stateProvider.state('home.list', {
url: '/list',
templateUrl: 'partial-home-list.html',
controller: function($scope) {
$scope.dogs = ['Bernese', 'Husky', 'Goldendoodle'];
}
});
When the URL changes, browser back and forward will be handled by UI Router.
To learn more, follow this great tutorial: http://scotch.io/tutorials/javascript/angular-routing-using-ui-router
Hope that helps :)
Upvotes: 1