Routing angular with .net core and RxJs switchmap- part 46
Now the problem is that the route
works if I access first the index.html file, but it does not route when entered directly
Trying to get from SPATemplate
https://github.com/ignatandrei/InfoValutar/commit/a364dc57653ac2ba04ab0596f1540a8f9fdb73f6
However, this will redirect ALL routes to index.html – including swagger and API. Trying to learn more – looking at the code.
I have observed that I have put
app.UseOpenApi();
app.UseSwaggerUi3();
after
this.route.params.pipe(
tap(rp => {
this.idBank = rp.id;
})
, switchMap((it) => this.bs.GetRates(it.id))
, tap(v => this.rates = v)
).subscribe();
What If I put first?
app.UseOpenApi();
app.UseSwaggerUi3();app.UseSpa(spa =>
And it works! https://github.com/ignatandrei/InfoValutar/commit/726ebd07095ea62387d4eeebb017b4f6ae4ab8e6
What I need more, is to retrieve the exchange rates for today for the selected bank.
The code to retrieve the bank id was:
this.route.params.subscribe(rp => {
this.idBank = rp.id;
}
);
I can put into subscribe the next call, but it will be not so nice ( subscribe into subscribe into subscribe)
this.route.params.subscribe(rp => {
this.idBank = rp.id;
this.bs.GetRates(it.id).subscribe( ….)
}
)
Instead of this, I use switchMap , pipe and tap
this.route.params.pipe(
tap(rp => {
this.idBank = rp.id;
})
, switchMap((it) => this.bs.GetRates(it.id))
, tap(v => this.rates = v)
).subscribe();
To fast show data, I use the Json pipe from Angular
<ul>
<li *ngFor=”let rate of rates”>
{{rate | json}}
</li>
</ul>
Modifications at https://github.com/ignatandrei/InfoValutar/commit/a27c7c7beb4ea10b9f8a522b01d558c6003d5386
Infovalutar
And one hour passes...(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
Leave a Reply