If you're looking to pass an object to a router (rather than a simple parameter), the key is using "states". Check out this link for more details.
<div *ngFor="let manga of mangas">
<a routerLink="/manga" [state]="manga">
</div>
In your ngOnInit, make sure you access it there. When using state to retrieve an object, typically you want the router to redirect to "home" if no object is present. If your manga object has a property named mangaId
, you can utilize this information within the subscription.
constructor(public activatedRoute: ActivatedRoute) {}
ngOnInit() {
this.activatedRoute.paramMap
.pipe(map(() => window.history.state)).subscribe(res=>{
console.log(res) // Check for additional property:navigationId
// Verify if an object was passed
// For instance, if your manga object has a property mangaId and it's not equal to 0
if (!res.mangaId)
router.navigate(['/home']
})
}