charsi
charsi

Reputation: 3847

Convert links to https. Angular 2+

My app pulls in thumbnail images from an api. The urls for the images are provided as http. I want to be able to convert these to https so the browsers don't complain about mixed content.

Is there a pipe or a better solution available in angular instead of converting in javascript?

Upvotes: 0

Views: 101

Answers (1)

Fateh Mohamed
Fateh Mohamed

Reputation: 21377

you can do it inside canActivate guard, i was looking for a better solution, but for the moment i use this and it works

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {

     if (location.protocol !== 'https:') {
         location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
     }
    ...

Upvotes: 3

Related Questions