我很难弄清楚MVC和Angularjs中的路由发生了什么。我看到Angularjs的1.0.x版本和1.3.x版本之间存在不同的行为。
我正在建立一个拥有多个“迷你水疗中心”的MVC网站。我有一个名为Registration的MVC控制器,它的路由是http://mysite/Registration。然后该控制器的索引视图呈现包含html和angular脚本的页面。
我想要有角度路线来渲染html模板,并按如下方式设置路由。
// this works in 1.0.x
var registrationModule = angular.module("registrationModule", []);
registrationModule.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/Registration/Members', {
templateUrl: '/templates/members.html',
controller: 'MembersController' });
$routeProvider.when('/Registration/Updates', {
templateUrl: '/templates/updates.html',
controller: 'UpdatesController' });
$locationProvider.html5Mode(true);
});
当我有上述路由和引用angularjs 1.0.x时,一切都按照我的预期工作。视图正确加载,并且它不会回发到/ Registration / * routes的服务器。
但是,当我引用角度1.3.x并具有以下路由时:
// this does not work in 1.3.x
var registrationModule = angular.module("registrationModule", ['ngRoute']);
registrationModule.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/Registration/Members', {
templateUrl: '/templates/members.html',
controller: 'MembersController' });
$routeProvider.when('/Registration/Updates', {
templateUrl: '/templates/updates.html',
controller: 'UpdatesController' });
$locationProvider.html5Mode(true);
});
视图不会加载到/ Registration / *路由上,它会回发到服务器,以便RegistrationController处理所有/ Registration / *路由。
版本之间的路由存在一些根本区别吗?我是否未能在新版本中正确实现角度路由?