Tag: 平均值栈

Angular2路由器和Express集成

我在使用Angular2路由器时遇到了问题,但是以前的问题似乎没有解决scheme。 我正在使用angular2-cli的最新版本。 当我将浏览器指向localhost:3000时,我得到了angular2-cli生成的通用“app works”消息。 当我尝试导航到我的一个子路由时,例如localhost:3000 / auth / login,它会将我redirect到同一个“应用程序作品”页面,而不是显示“login作品” 。 看看堆栈交换的其他问题,我认为这个问题在这里: app.get('*', (req, res) => { res.sendFile(path.join(__dirname, 'dist/index.html')); }); 当我用*replace*时,而不是redirect到我的目标页面,它给了我无法GET错误。 总之,我的问题是我的angular2路由集成到我的快速应用程序的url导航无法正常工作。 我在server.js中的快速代码如下所示: var express = require("express"); var app = express(); var bodyParser = require("body-parser"); var mongoose = require("mongoose"); var path = require("path"); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:true})); app.use(express.static(path.join(__dirname, 'dist'))); // Catch all other routes and return the index […]