1

I'm not sure if I have used the right terminology here but Is there a way I can get the base URL of my app?

My problem Is I have a login service that has a hardcoded redirectUrl now when I'm in development, I'm obviously using http://localhost:4200 but when I've published I'm using my website name https://mywebsite.com now Is there a way I can grab that and not anything after so like If I go to https://mywebsite.com/thisadad I only get back https://mywebsite.com?

Now I know I could have a function on the ngOnit of my app.component where I grab the URL on first load pass it to a service and then use it throughout the app but that wont work If I say enter the page at https://mywebsite.com/newpage is there a better way to do this??

The reason I'm using a hardcoded redirect is because I'm using auth0 as my authetication

Any help would be appreciated

Smokey Dawson
  • 8,827
  • 19
  • 77
  • 152
  • Hard-coding URL in app is nasty. Try something from this https://stackoverflow.com/questions/41922466/redirect-user-with-router-depending-on-logged-in-status – Lukáš Březina Jun 05 '18 at 00:22

1 Answers1

1

If i understand the situation currently, In your case you should use a global variable named 'environment'. Which you configure during build ( ng build ) More on this in this article: https://medium.com/beautiful-angular/angular-2-and-environment-variables-59c57ba643be

Alex
  • 365
  • 1
  • 4
  • 13