Amazon ec2 角度路由在URL地址栏上不起作用

Amazon ec2 角度路由在URL地址栏上不起作用,amazon-ec2,deployment,angular6,angular-routing,Amazon Ec2,Deployment,Angular6,Angular Routing,我做了一个带有布线组件的角度项目。我还处理了一些URL处理,比如用户手动点击URL:如果URL存在,它将转到应用程序路由模块.ts中定义的URL组件,如果URL不存在,它将显示代码PagenotFoundComponent中定义的错误页面。 e、 g 因此,当我手动点击localhost:4200/home时,它会显示HomeComponent页面,如果我点击localhost:4200/sdnbgbdfgbh,它会显示本地服务器上的PagenotfoundComponent页面 然后我转到这个

我做了一个带有布线组件的角度项目。我还处理了一些URL处理,比如用户手动点击URL:如果URL存在,它将转到应用程序路由模块.ts中定义的URL组件,如果URL不存在,它将显示代码PagenotFoundComponent中定义的错误页面。 e、 g

因此,当我手动点击localhost:4200/home时,它会显示HomeComponent页面,如果我点击localhost:4200/sdnbgbdfgbh,它会显示本地服务器上的PagenotfoundComponent页面

然后我转到这个链接:部署我的angular应用程序。我按照文档中的步骤进行操作。说

我的应用程序现在可以完全工作了,但当我手动键入url时,它会显示找不到Apache服务器页面。只是这个东西在Angular应用程序中不起作用


我已将我的应用程序部署在Apache服务器上端口80的AWS EC2上。

尝试重定向到路径
404
,如下所示:

const routes: Routes = [
   ...otherRoutes
   { path: '404', component: PagenotfoundComponent},
   { path: '**', redirectTo: '404'}
];
如果不工作,请尝试根据以下内容配置.htaccess:

记住,所有路径命中都应该通过apache配置中的
index.html

或者试试这篇文档,我希望它能帮助:

https://github.com/mgechev/angular-seed/wiki/Deploying-prod-build-to-Apache-2

你能用.htaccess内容更新你的问题吗?为了清楚地理解,需要查看.htaccess配置。我的.htaccess文件是空的。我在RewriteCond%{REQUEST\u FILENAME}-s[OR]RewriteCond%{REQUEST\u FILENAME}-l[OR]RewriteCond%{REQUEST\u FILENAME}-d RewriteRule^.*-[NC,l]RewriteRule^(.*)/index.html[NC,l]在.htaccess文件中,但它仍然不起作用。我按照您的建议编辑了app-routing.module.ts文件,并更新了.htaccess文件。我在“/var/www/html/”文件夹中添加了web.config文件,作为文件记录。我想尝试Nginx:使用try_文件,如Front Controller模式Web Apps中所述,修改为服务index.html:实际上我不知道在哪里必须这样做。而且该应用程序仍然无法故意命中URL或刷新页面。@Mohit,不要将nginx和apache混用在一个角度应用程序中。你能看懂这篇文档吗<代码>https://github.com/mgechev/angular-seed/wiki/Deploying-prod-build-to-Apache-2非常感谢您。这份文件适合我。我被困在这里面了。再次感谢你!我正在更新答案,如果我帮助您,请将此答案标记为已解决。谢谢。嗨@Fahim,我已经按照AWS EC2服务器上我的旧实例的步骤进行了操作。但现在我换到了新的AWS EC2实例,这一次,故意路由的链接失败了。
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
https://github.com/mgechev/angular-seed/wiki/Deploying-prod-build-to-Apache-2