angular - 部署在本地 tomcat 服务器上的 Angular 应用程序的 url 在将 url 粘贴到浏览器的新选项卡上时不会加载组件
问题描述
我已经在本地tomcat服务器中部署了一个角度应用程序并连接到一个使用身份服务器进行单点登录的spring应用程序,当我在eclipse上运行应用程序服务器并启动客户端应用程序时,应用程序可以无缝运行,但是当我复制 url 并将其粘贴到应用程序无法加载组件的浏览器的新选项卡上。
之前在浏览器的新标签上粘贴的 url 使用返回 404 错误,所以我搜索并发现我必须使用位置策略,并上传了一个新的 dist 文件,从那时起 url 不返回 404 而是无法加载(一个)组件。
这来自 app.routing.ts:
const routes: Routes = [
{ path: 'login', component: LoginComponent },
{path:'nav', component:NavBarComponent,
children:[
{path:'config', component:ConfigureComponent,
children:[
{path:'tenant', component:TenantComponent},
{path:'department', component:DepartmentComponent},
{path:'adminUser', component:DepartmentUserComponent},
{path:'setting', component:AdminSettingComponent},
{path: 'version', component: VersionManagementComponent},
{path:'eventType',component:EventTypeComponent},
{path:'workforceUser',component:WorkforceUserComponent},
{path:'dashboard',component:DashboardComponent},
{path:'eform',component:EFormComponent},
{path:'groups',component:GroupsComponent},
{path:'userProfile',component:UserProfileComponent}
]},
]},
{ path: '**', component: LoginComponent },
];
ConfigureComponent 是不加载的。
在 app.module.ts 实现定位策略:
import { Location, HashLocationStrategy, LocationStrategy } from
'@angular/common';
providers: [
{provide:LocationStrategy, useClass: HashLocationStrategy},
HttpClientService,
AppConfigService,
toastrService,
WorkforceUserService,
AuthGuard
]
我应该在路由中进行哪些更改,以便在我将 url 复制并粘贴到新选项卡上时不会错过 ConfigureComponent,当我刷新浏览器时也会发生同样的事情。
解决方案
您必须重写服务器的路由,以便将所有路由重定向到 index.html
推荐阅读
- csv - Pyspark在S3的子目录中加载多个csv
- node.js - 如何在 Node.js 中将大型 JSON 对象转换为类似于 console.log() 的字符串
- swift - 快速计时器目标以防止保留周期
- smtp - Gmail SMTP 服务器会定期响应 550 5.4.5 超出每日用户发送配额。n6sm796326oop.48
- javascript - 为什么 chrome 检查器在数组中显示一件事,但在展开时显示另一件事?香草JS
- python - 来自包含节点和连接python的文本文件的邻接矩阵
- python - 我试图比较 int 和 func 并且它给出了一个错误
- java - Google 表格中的数据刷新问题
- android - Android中悬停视图的圆角?
- javascript - 单击轮播指示器并显示相关幻灯片