Javascript url 小逻辑

情况1 : 

var xhr = new XMLHttpRequest();
xhr.open("GET", "/api/products", true);
xhr.send(null);

请求的 url 将会是 domain + "/api/products“

情况2 :

xhr.open("GET", "api/products", true);

请求的 url 将会是  baseUrl or 当前路径 + "/api/products“

情况1  好理解,只要url开头是 / 那么他就不过你在哪里,就是那domain 有点类似 ~/ 绝对路径的意思啦

情况2  如果有base url 那么它会优先用,如果没有的话它会一句你当前的path来继续 

所以当我们使用 angular + base url 的时候要特别小心哦

原文地址:https://www.cnblogs.com/keatkeat/p/5405695.html