【问题标题】:Nodejs 404 on angular state api, ui-router角度状态 api、ui-router 上的 Nodejs 404
【发布时间】:2015-10-28 06:21:45
【问题描述】:

我有 nodejs 角度应用程序。 Nodejs 正在运行服务器。当我转到http://localhost:3000/superadmin 时,我有一个带有 html5mode 的 ui 路由器设置,节点给出 404,但是当我到达 http://localhost:3000/#/superadmin 时,它重定向到 http://localhost:3000/superadmin 并且页面显示正常。

【问题讨论】:

    标签: angularjs node.js express


    【解决方案1】:

    您需要告诉 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 应用中定义的所有其他路由之下。

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多