I have base href set to /ui/ in my index.html. I try to call http.get('/api/endpoint') but angular requests /ui/api/endpoint insted. Is there any fix for such behaviour?
2 Answers
It depends on how you are hosting your app.
Lets say you have this URL:
http://ROOT_PATH/APP_PATH/ui/home
You can use 2 options to navigate to a specific point:
1 - '/api/endpoint' will resolve to http://ROOT_PATH/APP_PATH/ui/api/endpoint
2 - './api/endpoint' will resolve to http://ROOT_PATH/APP_PATH/ui/home/api/endpoint
So, for navigating to the APP path you can use ../api/endpoint that will resolve to http://ROOT_PATH/APP_PATH/api/endpoint.
4 Comments
'api/endpoint' it resolves to http://ROOT_PATH/ui/api/endpoint. .. did the trick.'api/endpoint' didn't work and I would like not to mark it as right if it doesnt work. If you leave only the part about ../api/endpoint I will vote :)<base href="/ui">From https://angular.io/docs/ts/latest/guide/router.html:
If the app folder is the application root, as it is for our application, set the href value in index.html exactly as shown:
<base href="/">
So when you set:
<base href="/ui/">
the root url will be: http://[host]/ui/