Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.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
Angular 请求的资源[/myapp/home]中的路由不可用_Angular_Tomcat_Routes_Web Deployment - Fatal编程技术网

Angular 请求的资源[/myapp/home]中的路由不可用

Angular 请求的资源[/myapp/home]中的路由不可用,angular,tomcat,routes,web-deployment,Angular,Tomcat,Routes,Web Deployment,我在tomcat中部署了angular应用程序,当我尝试访问像http://localhost:8083/myapp/home使用[routerLink]=“['/home']它工作正常,但当尝试刷新页面或直接访问时http://localhost:8083/myapp/home从浏览器中,我获得HTTP状态404请求的资源[/myapp/home]不可用,下面是我的路由配置: const routes: Routes = [ { path: 'myapp', redirectTo: &qu

我在tomcat中部署了angular应用程序,当我尝试访问像
http://localhost:8083/myapp/home
使用
[routerLink]=“['/home']
它工作正常,但当尝试刷新页面或直接访问时
http://localhost:8083/myapp/home
从浏览器中,我获得HTTP状态404请求的资源[/myapp/home]不可用,下面是我的路由配置:

const routes: Routes = [
  { path: 'myapp', redirectTo: "/home", pathMatch: "full" },
  { path: 'home', component: HomeComponent }
];
更新:

我在tomcat中添加了以下配置,404错误消失了,但现在当我刷新页面时,我被重定向到默认路由,即
myapp
,而我应该被重定向到当前路由:

<error-page> 
    <error-code>404</error-code>
    <location>/index.html</location>
</error-page>

404
/index.html

您需要将tomcat配置为重定向所有请求(404错误)到
index.html
因为你的应用程序是一个单页应用程序,我如何配置它?是的,这是可行的,但当我在“家”之外的另一条路径上刷新时,我会被重定向到默认路径,即MyApp。不幸的是,我从未使用tomcat托管单页应用程序,所以我不知道如何修复它。但我可以想象您只需要tomcat服务器的“正确”配置