Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在Heroku上使用Angular2路由器_Node.js_Angular_Heroku - Fatal编程技术网

Node.js 在Heroku上使用Angular2路由器

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

我已经在Heroku上部署了我的Angular2应用程序,所有功能都很好,但只有在我使用“www.example.com”格式时,如果我在搜索栏上输入“www.example.com/page”,它会给我“cannot GET/page”,在本地,所有功能都正常,但在Heroku上不会,我该怎么做才能让它工作呢?

当我上传了一个我制作的小应用程序到heroku时,我明白了这一点。我的快速修复方法是将hashbang添加到URL中,这样服务器就不会选择路由。只需将此添加到您导入路由的app.module.ts:

RouterModule.forRoot(路由,{useHash:true})

此外,在节点服务器中,如果不想在路由中使用哈希,可以将其添加到索引文件中,以便始终通过client index.html文件发送

app.use((req,res)=>res.sendfile(uu dirname+'/public/index.html')