简体   繁体   中英

angular.js Routing doesn't work on the server

I'm using ngRoute in my site, it work well on my computer (local) but on the server routing doesn't work. On my computer all my files are html, on the server i rename them as php. How can i fix it?

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider, $compileProvider) {
    $routeProvider
    .when("/", {
        templateUrl : "pages/main.php",
        controller: 'oneCtrl'
    })
    .when("/about", {
        templateUrl : "pages/about.php"
    })
    .when("/news", {
        templateUrl : "pages/news.php"
    })
});

Based on the error messages you're getting (as you said in the comments), the Angular library is not being loaded. Double-check the URL. Also in the browser dev tools, check the Network tab and see what error it shows. Probably a 404 not found .

After checking your website and the line where you said the error was occurring (line 156 of route.js ), change your code to this:

    $('.counter-one span').eq(0).html(value1 + ' ');
    $('.counter-two span').eq(0).html(value2 + ' ');

You did a search/replace for "html" to "php" but that also replaced the jQuery html() command. Just fix these two lines and you should be good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM