ngRoute的Angular Routing不适用于某些路由

在我的单页面应用程序中,我使用ngRoute进行angular度路由。 但是我正在面对angular度路由的一些问题。

configuration:

app.config(function($routeProvider,$locationProvider){ $locationProvider.html5Mode(true); $locationProvider.hashPrefix('!'); $routeProvider .when('/product',{ templateUrl : 'views/product/template/product.html', controller : 'productCtrl' }) .when('/product/add',{ templateUrl : 'views/product/template/add-product.html', controller : 'productCtrl' }) }); 

当我的路由path是/产品,那么一切都很好。 但是当我的路由path是/产品/添加,那么这似乎是一个错误。 但是,如果“/产品/添加”replace只是“/添加”,那么该路线也是可以的。 所以我不能识别什么是路由“/产品/添加”的主要问题。

错误:

 http://localhost:3000/product/views/product/template/add-product.html 404 (Not Found) 

在这里我看到了一个问题。 其他路线如下:

 http://localhost:3000/views/product/template/product.html 

但是服务器连接后错误路由有/ product。

需要一些澄清和解决这个问题。

提前致谢

用错误页面正确configuration路由。 你可以按照这个小提琴的例子。

HTML

 <div ng-controller="MainCtrl"> <ul> <li><a href="/product">product</a></li> <li><a href="/product/add">add</a></li> <li><a href="/other">Other</a></li> </ul> <ng-view></ng-view> </div> 

angular

 var app = angular.module( "myApp", [] ); app.config( function ( $routeProvider,$locationProvider ) { $locationProvider.html5Mode(true); $locationProvider.hashPrefix('!'); $routeProvider .when( '/product', { template: 'I am product root' } ) .when( '/product/add', { template: 'Adding a product' } ) .when( '/other', { template: 'Other pages' } ) .otherwise( { redirectTo: '/product' } ); }); app.controller( 'MainCtrl', function ( $scope ) { }); 

更多https://jsfiddle.net/zahiruldu/jLdce3vj/186/

您可以使用UI路由器正确处理父路由,这将为您提供嵌套的路由function。