Live Traffic Feed

Monday, March 19, 2018

Redirect every request to https from http in angular 5

Leave a Comment
Write in app.component.ts file:

import { environment } from '../environments/environment.prod';



ngOnInit() {
    if (!isDevMode() && environment.production) {
      if (location.protocol === 'http:') {
        window.location.href = location.href.replace('http', 'https');
      }
    }
}


Write your environment.prod.ts file like:
export const environment = {
production: true
};
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment