我正在使用Angular5,但是在浏览器中返回前一页时会丢失数据。我的意思是,上一个组件应该能够重新加载其数据。
例如:
在我的组件中:
import { Location } from '@angular/common';
@Component({
selector: 'app-mant-cert-certificacion',
templateUrl: './mant-cert-certificacion.component.html',
styles: []
})
export class MantCertCertificacionComponent implements OnInit {
constructor(private location: Location) {
}
goBack() {
this.location.back();
console.log( 'goBack()...' );
}
}
mant-cert-certificacion.component.html:
<a href="javascript:void(0)" (click)="goBack()">
<- Back
</a>
这个组件是从我的路由模块调用的。当我点击“返回”按钮时,我希望显示上一个已加载数据的组件。
我的路由模块:
export const routes: Routes = [
{ path: 'xxxx', children: [
{ path: '', component: XComponent},
]},
{ path: 'yyyy', children: [
{ path: 'contractdetail/', component: MantCertCertificacionComponent}
]}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class MantenedoresCertRoutingModule { }
有什么想法吗?
之前的组件将是“XComponent”。信息的内容(属性或变量)并不重要,我只想加载它们的数据。
谢谢!