JavaScriptServices icon indicating copy to clipboard operation
JavaScriptServices copied to clipboard

Resolve router on SSR

Open ccaymaz opened this issue 9 years ago • 1 comments

Hi,

I am having some issue while SSR. I added 5 seconds delay on "/api/SampleData/WeatherForecasts" and added router resolve on '/fetchdata' link.

When I hit fetchdata link from home page, I wait 5 seconds to see actual fetchdata page. Working correctly. But if I refresh my screen while I am on fetchdata page, I immediately receive content of the fetchdata page and then after 5 seconds, I get the data.

Fetchdata page should wait until "/api/SampleData/WeatherForecasts" return data. I am currently using nguniversal/aspnetcore-engine : beta-2 version for SSR.

My resolver is like that:

@Injectable()
export class FetchDataResolve implements Resolve<any> {
  
    constructor(
        private http: Http,
         @Inject('ORIGIN_URL') private originUrl: string) { }
  
    resolve(route: ActivatedRouteSnapshot) {
        return this.http.get(this.originUrl +'/api/SampleData/WeatherForecasts').map(res => res.json());
  }
}

I used it in the app.module.shared.ts like that

.......
            { path: 'fetch-data', component: FetchDataComponent, resolve: { fetchdata: FetchDataResolve} },
.......

And last one is my fetchdata.component.ts

    constructor(
        private route: ActivatedRoute) {
        this.forecasts = this.route.snapshot.data['fetchdata'] as WeatherForecast[];
    }

ccaymaz avatar Jun 07 '17 22:06 ccaymaz

nguniversal/aspnetcore-engine is not used in the templates in this repo, so if it's not behaving as you want, could you please report the issue to the nguniversal/aspnetcore-engine project instead?

If I'm misunderstanding and you're able to track this down to some specific bug in some code in this repo, could you please re-open with details of which code here is broken? Thanks!

SteveSandersonMS avatar Jun 08 '17 08:06 SteveSandersonMS