无法匹配AngularJS中的路线

时间:2015-02-19 19:23:31

标签: javascript angularjs

我的app.js中有以下代码:

var myApp = angular.module('myApp', ['ngRoute'])

myApp.config(['$routeProvider', '$locationProvider',
  function($routeProvider, $locationProvider) {
    $routeProvider.
      when('/products', {
        templateUrl: '/angularjs/public/angular/views/product.html'
      }).
      otherwise({
        templateUrl: '/angularjs/public/angular/views/home.html'
      });
    $locationProvider.html5Mode(true);
  }]);

当我在http://localhost/angularjs/public回家时,.otherwise正确启动。

如果我转到http://localhost/angularjs/public/products,则不会发生任何事情,或者更确切地说,我相信再次调用.otherwise,因为会显示home.html视图。此外,batarang's控制台中没有错误。

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

您需要在路线中的产品slug中添加“public”

when('public/products', {
    templateUrl: '/angularjs/public/angular/views/product.html'
  }).