Note: Before asking this question i went to lot of other answers and blogs. i also visited and understood. Make AJAX request before bootstrapping Angular2 application properly.. With introduction to bootstrapModule all the previous answers doesn't work. and all answers has APIs which are not available in angular2's stable release
Question: I am trying to solve very basic problem with login/authentication. If user copy the link http://domain.com/login and if he is already logged in I want to redirect him to home.
The way i tried is on route change I check authentication and then redirect. but that takes time as one has to wait till response comes back. what i want is even before the angular bootstrap happens i want to make an ajax call and get the current user from server. if user is not logged in that call will not give any user and that information should be available to Angular via some service let say authService. so at any place we can use authService.user to check if user is logged in or not.
not i can make ajax call with native JS xmlHttpRequest and store use in window object. and on bootstrap access that window object in authService that works fine. but i think using window object is not a good solution.
please guide me what would be the possible solution.
below is my main.js and i have to use bootstrapMoudle and not bootstrap(component);
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule)
.catch(err => console.error(err));