gem "turbolinks"
gem "angular-turbolinks"
//= require angular-route
//= require angular-turbolinks
var app = angular.module('...', [..., 'ngRoute', 'ngTurbolinks'])
app.config([
"$locationProvider", function($locationProvider) {
$locationProvider.html5Mode(true);
}
]);
(optional) Broadcast angular $destroy for you to remove any global listeners (window, pending http, etc)
$(document).on('page:before-change', ->
angular.element("body").scope().$broadcast("$destroy")
)
- This is a first stab just to try to get around the '10 $digest() iterations reached using $locationWatch' errors I was receiving when using turbolinks with angular when using the approach of re-bootstrapping the ng-app on turbolinks page:load
- angular/angular.js#3915
- angular/angular.js#2815 (among others)
- none of the suggested fixes worked for me and this was happening on chrome
- This approach uses the angular $location/$locationProvider services for click tracking and pushState, steals the $locationChangeStart event and runs the changed url through turbolinks methods
- Does not support any of the turbolinks caching
- Eventually im hoping angular $locationWatch can play nice with external plugins using pushState...
- add support for turbolinks redirection logic (referer not working properly (ie. redirect_to :back))