Fixed It checking for an xhr request fixed the infinite loop
get '/about' do
erb :about, layout: !request.xhr?
end
I am using angular js and sinatra to create a page. Angular is handling my routes and calling the templates
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/home', {templateUrl: '/home'}).
when('/about', {templateUrl: '/about'}).
when('/work', {templateUrl: '/work'}).
when('/blog', {templateUrl: '/blog'}).
when('/contact', {templateUrl: '/contact'}).
otherwise({redirectTo: '/'});
}]);
When I go to /#/blog , the template loads fine. The content is provided by sinatra
get '/blog' do
'This is the work page!'
end
However, I get infinite view loads when doing the about page. The about page is provided by
get '/about' do
erb :about
end
Namespace your "private" routes, else /contact is going to trigger angular's router again and again etc.
get '/about' do
erb :about, layout: !request.xhr?
end
the previous code load the layout which contained the angular js code. the js code called the /about again and it repeated. Since the call from angular js route is xhr, checking it fixed the problem.