Angular 允许忽略某些URL

Angular 允许忽略某些URL,angular,typescript,.htaccess,search-guard,Angular,Typescript,.htaccess,Search Guard,我的Angular应用程序位于example.com上,后端位于example.com/api上。我的问题是,当我想用URL向服务器发送请求时,我得到了一个错误HttpErrorResponse。我刚刚在浏览器中键入了相同的URL,但我将被重定向到主页。所以我可能会遇到这个错误,因为我的服务器永远无法访问 如何允许Angular使用example.com/api/*忽略所有URL 我的文件app-routing.modules.ts如下所示: const routes:routes=[ {路径:

我的Angular应用程序位于example.com上,后端位于example.com/api上。我的问题是,当我想用URL向服务器发送请求时,我得到了一个错误HttpErrorResponse。我刚刚在浏览器中键入了相同的URL,但我将被重定向到主页。所以我可能会遇到这个错误,因为我的服务器永远无法访问

如何允许Angular使用
example.com/api/*
忽略所有URL

我的文件app-routing.modules.ts如下所示:

const routes:routes=[
{路径:'',组件:HomeComponent,canActivate:[HomeGuard]},
{路径:'login',组件:LoginComponent,canActivate:[LoginGuard]},
{path:'register',component:RegisterComponent,canActivate:[LoginGuard]},
{路径:'search',组件:SearchComponent,canActivate:[SearchGuard]},
{路径:'edit profile',组件:ProfileComponent,canActivate:[SearchGuard]}
];
@NGD模块({
导入:[RouterModule.forRoot(路由,{scrollPositionRestoration:'enabled'}],
导出:[路由模块]
})
导出类AppRoutingModule{}
.htaccess:


添加此重定向将获取与上述路径不匹配的任何url,并将其重定向到主页。或者,根据您的偏好,您可以创建一个404或错误组件,以显示
{path:'**',component:ErrorComponent}

const routes:routes=[
{路径:'',组件:HomeComponent,canActivate:[HomeGuard]},
{路径:'login',组件:LoginComponent,canActivate:[LoginGuard]},
{path:'register',component:RegisterComponent,canActivate:[LoginGuard]},
{路径:'search',组件:SearchComponent,canActivate:[SearchGuard]},
{路径:'edit profile',组件:ProfileComponent,canActivate:[SearchGuard]},
{路径:'**',重定向到:'/',路径匹配:'full'}

];添加此重定向将获取与上述路径不匹配的任何url,并将其重定向到主页。或者,根据您的偏好,您可以创建一个404或错误组件,以显示
{path:'**',component:ErrorComponent}

const routes:routes=[
{路径:'',组件:HomeComponent,canActivate:[HomeGuard]},
{路径:'login',组件:LoginComponent,canActivate:[LoginGuard]},
{path:'register',component:RegisterComponent,canActivate:[LoginGuard]},
{路径:'search',组件:SearchComponent,canActivate:[SearchGuard]},
{路径:'edit profile',组件:ProfileComponent,canActivate:[SearchGuard]},
{路径:'**',重定向到:'/',路径匹配:'full'}
];
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