Node.js 在Heroku上使用Angular2路由器
我已经在Heroku上部署了我的Angular2应用程序,所有功能都很好,但只有在我使用“www.example.com”格式时,如果我在搜索栏上输入“www.example.com/page”,它会给我“cannot GET/page”,在本地,所有功能都正常,但在Heroku上不会,我该怎么做才能让它工作呢?当我上传了一个我制作的小应用程序到heroku时,我明白了这一点。我的快速修复方法是将hashbang添加到URL中,这样服务器就不会选择路由。只需将此添加到您导入路由的app.module.ts:Node.js 在Heroku上使用Angular2路由器,node.js,angular,heroku,Node.js,Angular,Heroku,我已经在Heroku上部署了我的Angular2应用程序,所有功能都很好,但只有在我使用“www.example.com”格式时,如果我在搜索栏上输入“www.example.com/page”,它会给我“cannot GET/page”,在本地,所有功能都正常,但在Heroku上不会,我该怎么做才能让它工作呢?当我上传了一个我制作的小应用程序到heroku时,我明白了这一点。我的快速修复方法是将hashbang添加到URL中,这样服务器就不会选择路由。只需将此添加到您导入路由的app.modu
RouterModule.forRoot(路由,{useHash:true})
此外,在节点服务器中,如果不想在路由中使用哈希,可以将其添加到索引文件中,以便始终通过client index.html文件发送
app.use((req,res)=>res.sendfile(uu dirname+'/public/index.html')代码>