簡體   English   中英

制作一個按鈕到go后頁

[英]Making a button to go back page

我正在制作一個從 API 加載數據的 agular 應用程序,當我將 go 加載到另一條路由並將 go 返回到表路由時,數據不存在。

有沒有辦法改變路線而不丟失數據?

<button [routerLink]="['/home']">
   <i class="bx bx-left-arrow-alt" id="icone"></i>
</button>

現在我只是使用 routerLink 來更改路由。

我正在使用 angular 15。

import {Component} from '@angular/core';
import {Location} from '@angular/common';

@Component({selector: 'app-second-part',
templateUrl: './second-part.component.html',
styleUrls: ['./second-part.component.css']})
class SecondPartComponent {

 constructor(private location: Location){}

 goBack() {
  this.location.back();
 }
}

這是一個解析器文件

export class ReadyLinesResolver implements Resolve<any> { 

 resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> | Promise<any> | any {
   // return your API response
 }  
}

這是你的路由器:

{
   path: '',
   resolve: {userInfo: UserInfoResolver},
},

您必須在構造函數中注入 Router 模塊。

這是你的 ngOnInit 組件:

this.router.data.subscribe(res=> {
  // check here and find your property name
})

將您的數據返回到變量中並使用它們

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM