【发布时间】:2015-10-28 06:21:45
【问题描述】:
我有 nodejs 角度应用程序。 Nodejs 正在运行服务器。当我转到http://localhost:3000/superadmin 时,我有一个带有 html5mode 的 ui 路由器设置,节点给出 404,但是当我到达 http://localhost:3000/#/superadmin 时,它重定向到 http://localhost:3000/superadmin 并且页面显示正常。
【问题讨论】:
我有 nodejs 角度应用程序。 Nodejs 正在运行服务器。当我转到http://localhost:3000/superadmin 时,我有一个带有 html5mode 的 ui 路由器设置,节点给出 404,但是当我到达 http://localhost:3000/#/superadmin 时,它重定向到 http://localhost:3000/superadmin 并且页面显示正常。
【问题讨论】:
您需要告诉 express 将所有到达服务器的请求重定向到您的 index.html
server.js 文件中的示例:
var express = require('express');
var app = express();
app.all('/*', function(req, res) {
res.sendfile('index.html'); // or the name of your angular app html file
});
app.listen(3000);
您需要确保将 app.all() 置于您在 express 应用中定义的所有其他路由之下。
【讨论】: