I'm making an agular app which load data from an API, and when I go to another route and go back to table route the data is not there.
Is there some way to change route and not losing data?
<button [routerLink]="['/home']">
<i class="bx bx-left-arrow-alt" id="icone"></i>
</button>
Now I'm just using a routerLink to change routes.
And I'm using 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();
}
}
this is a resolver file
export class ReadyLinesResolver implements Resolve<any> {
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> | Promise<any> | any {
// return your API response
}
}
this is your router:
{
path: '',
resolve: {userInfo: UserInfoResolver},
},
you must inject the Router module in the constructor.
this is your ngOnInit component:
this.router.data.subscribe(res=> {
// check here and find your property name
})
return your data in a variable and use them
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.