无法匹配AngularJS中的路由

Unable to match route in AngularJS

本文关键字:路由 AngularJS      更新时间:2024-02-19

我的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控制台中也没有抛出任何错误。

可能是什么问题?

您需要在路线中向产品段塞添加"public"

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