Angular Route Infinite Loop

前端 未结 1 601
悲&欢浪女
悲&欢浪女 2020-12-18 22:21

For some reason when I have a dynamic property in my route and access that page I get stuck in an infinite loop where that page will continuously request itself.

<         


        
相关标签:
1条回答
  • 2020-12-18 22:51

    Silly me I realized the problem. I guess it makes sense but the template url needs to have a forward slash in front of it when the page is multiple "directories" deep.

    .config(["$routeProvider", "$locationProvider", function($routeProvider, $locationProvider)
    {
        $locationProvider.html5Mode(true);
    
        $routeProvider.when("/", {
            templateUrl: "/pages/index.html",
            controller: "IndexCtrl"
        }).when("/listhome", {
            templateUrl: "/pages/listhome.html",
            controller: "ListHomeCtrl"
        }).when("/profile", {
            templateUrl: "/pages/profile.html",
            controller: "ProfileCtrl"
        }).when("/newlist", {
            templateUrl: "/pages/newlist.html",
            controller: "NewListCtrl"
        }).when("/userlists/:id", {
            templateUrl: "/pages/userlists.html",
            controller: "UserListsCtrl"
        }).otherwise({
            redirectTo: "/"
        });
    }]);
    

    Hopefully that helps someone else with a similar problem.

    0 讨论(0)
提交回复
热议问题