angular - 在以角度 4 重定向到新路线之前获取当前路线的数据
问题描述
实际要求: 在重定向到新路由之前,我想触发当前路由(组件)的功能。此功能实际上是用于保存当前路由中存在的表单的值。(在重定向到新路由(组件)之前自动保存当前组件的数据)。
我的解决方案: 在重定向到新路由之前,我将检查当前路由的数据,该数据将包含当前路由名称和要触发的函数名称。
挑战: 如何在重定向到新路由之前获取当前路由的数据?
下面是示例代码:
路由.ts
export const AppRoutes: Routes = [
{ path: 'overviewHistory', component: OverviewHistoryComponent,data: { state: 'overviewHistory',function:'abc' }},
{ path: 'leadDetails', component: LeadInformationComponent, data: { state: 'leadDetails',function:'abc1' } },
{ path: 'checeklist', component: CheckListComponent,data: { state: 'checeklist',function:'abc2' }},
{ path: 'teamManagement', component: TeamManagementProfileComponent,data: { state: 'teamManagement',function:'abc3' }},
{ path: 'directorDetails', component: DirectorOtherpartyDetailComponent,data: { state: 'directorDetails',function:'abc4' }},
{ path: 'addressDetails', component: AddressDetailsComponent,data: { state: 'addressDetails',function:'abc5' }},
];
HTML:
<div id="site-content" class="content full-width" [@routerTransition]="getState(o)" >
<router-outlet #o="outlet" (activate)="optionChange(o)"></router-outlet>
</div>
TS:
optionChange(outlet){
// Some logic....
}
请帮助实现这一目标。还建议是否有任何新方法可以实现实际要求。
解决方案
推荐阅读
- git - 两个远程仓库之间的 git push
- html - 存在滚动条时,Bootstrap 4 侧边栏列被切断
- docusignapi - DocuSign - 使用 eSignature REST API v2.1 获取签名 URL
- c# - 我正在使用统一制作我的第一个 2d 游戏(我是菜鸟),我试图制作一个死亡屏障,将角色传送回开始
- python - Python Numpy 在两行之间插入一个值
- powershell - 检查 XML Node 是否为真,如果是,则执行 SQL 语句
- if-statement - C++ 返回类型推导与速记 IF 语句问题
- html - 将图像与相同大小的文本垂直对齐
- c++ - 使用 swig 从 c++ 调用 go
- docker - 当 Docker 桌面在 WSL2 中运行时,bash 中的长工作目录