2

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 2

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I would love if it have worked like this, but when I request 'api/endpoint' it resolves to http://ROOT_PATH/ui/api/endpoint. .. did the trick.
@Krever, can you vote this answer as the right one? Thanks!
Yeah, sure, but the thing about '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 :)
Ok, I'll remove the third option! That is because is an ajax call and the Angular get the host based on <base href="/ui">
1

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.