使用angular2在http.get中的绝对URL [英] Absolute url in http.get with angular2
问题描述
我在index.html中将基本href设置为/ui/
.我尝试调用http.get('/api/endpoint')
,但插入了角度请求/ui/api/endpoint
.这样的行为有什么解决办法吗?
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?
推荐答案
这取决于您如何托管应用.
It depends on how you are hosting your app.
让我们说您拥有以下网址:
Lets say you have this URL:
http://ROOT_PATH/APP_PATH/ui/home
您可以使用2个选项导航到特定点:
You can use 2 options to navigate to a specific point:
1-'/api/endpoint'
将解析为http://ROOT_PATH/APP_PATH/ui/api/endpoint
2-'./api/endpoint'
将解析为http://ROOT_PATH/APP_PATH/ui/home/api/endpoint
因此,要导航至APP路径,可以使用../api/endpoint
,它将解析为http://ROOT_PATH/APP_PATH/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
.
这篇关于使用angular2在http.get中的绝对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!