express应用程序中的两个有角度的应用程序(错误:无法匹配任何路由.URL段:)



嗨(很抱歉我的英语不是我的母语(

和许多人一样,我在express中运行了一个angular应用程序,并决定为管理员和用户使用一个单独的angular应用(主要是因为我在导航栏中获得了太多路线(我现在有两个应用程序运行良好,当我使用";ng发球";(每个都有自己的导航(。当我尝试将两个应用程序都放入express时,问题出现了。

我做了这篇文章,

app.use('/',express.static(path.join(__dirname, 'gbv'))); //the output from "ng build" app1
app.use('/admin',express.static(path.join(__dirname, 'admin'))); // the output from "ng build" admin and users app
var indexRouter = require('./routes/index'); //also use this index file to send files
app.use('/', indexRouter);

routes/index.js文件具有以下

router.route('/')
.options( (req, res) => {
res.sendStatus(200);
})
.get( (req, res, next) => {
//res.render('index', { title: 'Express' });
res.sendFile(path.join(__dirname,"../gbv/index.html"));
});
...
router.route('/admin')
.options( (req, res) => {
res.sendStatus(200);
})
.get( (req, res, next) => {
//res.render('index', { title: 'Express' });
res.sendFile(path.join(__dirname,"../admin/index.html"));
return;
});

我可以毫无问题地访问我的网站http://localhost/,但当我访问http://localhost/admin时,我收到了以下错误:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'admin'

第一个app1的相同导航仍然是

遗憾的是,我还不能展示照片。。。

奇怪的是,通过检查网络控制台,我可以检查文件是否已发送。似乎第一个app1的导航仍然存在,而不是带来app2的导航。我怀疑这与这两个文件被称为index.html的事实有关,这会导致混乱。我尝试更改输出文件的名称;ng构建";。但angular不允许我这么做。

我使用的是快递4.16.1角度10.2.2

有人有同样的问题吗?

xD由于某种原因,它通过更改为来工作

app.use(express.static(path.join(__dirname, 'gbv')));
app.use(express.static(path.join(__dirname, 'admin')));

并使用

ng build --output-hashing all

在构建内建angular时。

最新更新