静态路由在ExpressJS中不起作用

时间:2014-02-03 15:16:00

标签: node.js angularjs express angularjs-routing

我有一个小应用程序,我遇到静态路由问题:

这是我的app.js配置:

employeesApp.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.
            when('/employees', {
                templateUrl: '/partials/employees_list.html',
                controller: 'EmployeesCtrl'
            }).
            when('/employees/add_new', {
                templateUrl: '/partials/employess_add_new.html',
                controller: 'EmployeeAddNewCtrl'
            }).
            when('/employees/:employeeId', {
                templateUrl: '/partials/employees_details.html',
                controller: 'EmployeeDetailsCtrl'
            }).
            otherwise({
                redirectTo: '/employees'
            });
    }]);

控制器:

EmployeesControllers.controller('EmployeeAddNewCtrl', ['$scope',
    function($scope) {

    }]);

服务器端:

var express = require('express');
var app = express();
var mongoose = require('mongoose');

// mongodb connection and app configuration
mongoose.connect('mongodb://localhost/test');

app.configure(function () {
    app.use(express.static(__dirname + '/app'));
    app.use(express.logger('dev'));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
});


// application
app.get('*', function(req, res) {
    res.sendfile('./app/index.html'); // load the single view file, angular will handle other views
});

主要问题是第一个(/ employees)和第三个路径(/ employees /:employeeId')正常工作,但第二个路径('/ employees / add_new')无效,我最终在应用程序不断调用服务器的页面,我的浏览器吃整个内存和崩溃。

这是我的文件层次结构:

Application
---app
------css
------js
--------------app.js
------partials
--------------employees_list.html
--------------employees_add_new.html
--------------employees_details.html
------lib
---server.js

1 个答案:

答案 0 :(得分:0)

这绝对是

的错字
       `when('/employees/add_new', {
            templateUrl: '/partials/employess_add_new.html',
            controller: 'EmployeeAddNewCtrl'
        }).`

应为employees