Angular JS routing makes infinite loop

theroom101

i got Django server with

urls.py

urlpatterns = [
  url('^', IndexView.as_view(), name='index')
]

landing/urls.py

urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url('^.*', include("landing.urls"))
]

views.py

class IndexView(TemplateView):
template_name = 'landing/header.html'

def get_context_data(self, **kwargs):
    context = super(IndexView, self).get_context_data(**kwargs)
    context['meals'] = get_data()

    return context

header.html

<html lang="en" ng-app="KolyadaApp">

<div ng-view></div>
<a class="navbar-brand" ng-href="/landing">landing</a>
<a ng-href="#/menu">menu</a>
<a ng-href="#/week">week</a>

app.js

'use strict';

/* Controllers */
var KolyadaApp = angular.module('KolyadaApp', ['ngRoute',    'ngResource']);

angular.
  module('KolyadaApp').
  config(['$locationProvider', '$routeProvider', '$interpolateProvider',
    function config($locationProvider, $routeProvider, $interpolateProvider) {
    $interpolateProvider.startSymbol('{$');
    $interpolateProvider.endSymbol('$}');

    $routeProvider.
        when('/', {
            templateUrl: function(route) {

                console.log(route);

                return '/';
            }
        }).
        when('/menu', {
          templateUrl: '/menu.html'
        }).
        when('/week', {
          templateUrl: '/week.html'
        }).
        otherwise('/', {
            redirectTo:'/'
        });
}
]);

What I got: after loading page, I can do nothing with links, Console log periodically tells me about call stack overflow. And it hard to close the tab.

Well, after some time of searching answer, and placing '/' everywhere where I can, I decide to ask you. Please tell where I'm wrong.

Thank you.

Pureferret

This is your issue, I believe:

urls.py

urlpatterns = [
  url('^', IndexView.as_view(), name='index')
]

landing/urls.py

urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url('^.*', include("landing.urls"))  # Circular reference
]

You're reloading landing.urls inside your include tag everytime you load landing/urls.py.

Did you mean for that line to be in urls.py? If so you'll need to alter one or both so they don't conflict (i.e. ^ and ^.* both match an empty string).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related