AngularJS不会渲染$ routeProvider中指定的视图

时间:2018-02-15 16:08:22

标签: javascript angularjs angularjs-ng-route

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

myApp.config(function ($locationProvider) {
    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    });
});

myApp.config(function ($routeProvider) {
    $routeProvider
        .when("", {
            templateUrl: "Views/Employee/Employees.html",
            controller: "EmployeesController"
        }).otherwise({ redirectTo: 'Views/Employee/Employees' });
});

它路由了否则提到的URL,而不是.when

中提到的URL

1 个答案:

答案 0 :(得分:0)

Angular应用的根路线为"/",而不是""

然后,redirectTo将路由提供程序中定义的路由作为值。

myApp.config(function ($routeProvider) {
    $routeProvider
        .when("/", {
            templateUrl: "Views/Employee/Employees.html",
            controller: "EmployeesController"
        })
        .otherwise({ redirectTo: '/' });
});