我在index.html 中将基本href 设置为/ui/
。我尝试调用 http.get('/api/endpoint')
但插入了 Angular 请求 /ui/api/endpoint
。对于这种行为有什么解决办法吗?
最佳答案
这取决于您托管应用程序的方式。
假设您有这个网址:
http://ROOT_PATH/APP_PATH/ui/home
您可以使用 2 个选项导航到特定点:
1 - '/api/endpoint'
将解析为 http://ROOT_PATH/APP_PATH/ui/api/endpoint
2 - './api/endpoint'
将解析为 http://ROOT_PATH/APP_PATH/ui/home/api/endpoint
因此,要导航到应用程序路径,您可以使用 ../api/endpoint
它将解析为 http://ROOT_PATH/APP_PATH/api/endpoint
。
关于angular - http.get 中的绝对 url 与 angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39234735/