在expressjs中parsingurl参数 – angularjs应用程序

在expressjs和AngularJs项目中遇到了路由问题。

这不是一个单一的页面应用程序,我不使用任何视图引擎,如玉。

我们只是使用纯HTML。

我正在使用密码重置function,用户可以通过单击电子邮件提供的链接重置密码。 所以我认为在Angular中不会有任何路线变化事件(如果我错了,请纠正我)。

我的明确configuration如下。

routes = require('./routes/index'); app.configure(function () { app.use(express.static(__dirname + '/app')); app.use('/css', express.static(__dirname + '/app/css')); app.set('views', __dirname + '/app'); app.set("view options", { layout: false }); app.engine('.html', require('ejs').__express); app.set('view engine', 'html'); app.use(express.favicon()); //app.use(require('connect').bodyParser()); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); }); // Routes app.get('/', routes.index); app.get('/resetpassword.html/:resetcode', function (req, res) { console.log("reset code: " + req.params.resetcode); res.render('resetpassword.html/' + req.params.resetcode); }); app.get('/api', function (req, res) { res.send('Ecomm API is running'); }); // JSON API app.post('/registeruser', usersApi.registerUser); app.post('/api/login', usersApi.logIn); app.post('/api/addgame', gamesApi.addGame); app.get('*', routes.index); // Start server app.listen(2221, function () { console.log("Express server listening on port %d in %s mode", 2221, app.settings.env); }); 

和index.js

 exports.index = function(req, res){ res.render('home.html'); }; // Always rending index.html which needs to be fixed. 

和AnghularJs的app.js如下

 app.config(function ($routeProvider) { $routeProvider .when('/', { templateUrl: 'home.html' }) .when('/resetpassword.html/:resetcode', { templateUrl: '/resetpassword.html', controller: 'ResetPasswordCtrl' }) .otherwise({ redirectTo: '/' }); }); 

我得到500内部错误或查看未find错误。

任何build议,请。

您将密码连接到您传递的视图名称,因此Express无法find视图并返回500错误。 您需要将数据作为附加参数作为对象传递给render函数:

 res.render('resetpassword.html', {resetcode: req.params.resetcode} ); 

然后在你的视图中直接使用resetcode ,例如

 <span><%= resetcode %></span>