Node.js / Express将全部redirect到angular度2页面
我正在用Node.js和Express创build一个Angular 2应用程序。
我遇到的问题是我的路线文件不能使用通配符。 每次我访问页面的其他东西/
(例如/test
)它说以下内容: ReferenceError: path is not defined
我的server.js:
const express = require('express'); const app = express(); const path = require('path'); const routes = require('./routes'); const data = require('./articles.json'); app.use(express.static(path.join(__dirname, '/dist'))); app.use('/', routes); app.listen(8080, function () { console.log('App started on port 8080'); });
我的/routes/index.js:
const routes = require('express').Router(); routes.get('*', function (req, res) { res.sendFile(path.join(__dirname + '/dist/index.html')); }); module.exports = routes;
那么我在这里做错了什么?
你也需要在你的index.js中需要path包
/routes/index.js
const path = require('path'); const routes = require('express').Router(); routes.get('*', function (req, res) { res.sendFile(path.join(__dirname + '/dist/index.html')); }); module.exports = routes;
- 获取“ProgressEvent”,而不是在Angular + NodeJS中响应json
- 通过咕噜开始量angular器
- 如何将基于Angular CLI的ng2 / 4应用程序烧烤到Node / Express中,并具有单一回声系统来开发/运行/debugging服务器/客户端应用程序?
- 如何在node.js服务器中提供angular2应用程序
- Angular JWT Profile用户(获得JSON领域)
- 量angular器asynchronous等待不是一个function
- 如何在WebStorm中debuggingangular度量angular器testing
- 错误TS2307:找不到模块'bluebird'
- 量angular器browser.get()不导致URL与致命错误exception